如何在VB.NET中处理字符串连接中的空对象?

如何在VB.NET中处理字符串连接中的空对象?,.net,vb.net,string,nullreferenceexception,string-concatenation,.net,Vb.net,String,Nullreferenceexception,String Concatenation,如果ProcessRequest方法中存在问题,并且它返回null,则下一行将不起作用,并将引发NullReference异常 获取响应的最简单方法是什么。如果响应为空,则消息计算为空字符串。您可以使用内联: 但在我看来,如果。。else子句&没有任何东西等同于&“” 因此,IMO最简单的方式是: Msgbox("This is the response message: " & If(response Is Nothing, "", response.Message)) Msgbox

如果ProcessRequest方法中存在问题,并且它返回
null
,则下一行将不起作用,并将引发
NullReference
异常

获取
响应的最简单方法是什么。如果
响应
,则消息计算为空字符串。

您可以使用内联:

但在我看来,如果。。else
子句

&没有任何东西等同于&“”

因此,IMO最简单的方式是:

Msgbox("This is the response message: " & If(response Is Nothing, "", response.Message))
Msgbox("This is the response message: " & If(response Is Nothing, "", response.Message))
Dim response As MyClass = obj.ProcessRequest(strRequest)
Msgbox("This is the response message: " & response?.Message)