在我们的代码库中,有一个函数应该返回一个对象或什么都不返回。
确切的代码是:
Return Nothing
调用方法看起来像这个
myObj = theClass.function()
if myObj <> nothing then // fails
我在C#中遗漏了什么吗?我会使用if not null检查,为什么在VB.net中会失败,我如何检查func的返回val是否为空?
提前感谢
为了比较引用(和Nothing
),需要使用Is
和IsNot
,而不是=
和<>
。
即:
If myObj IsNot Nothing Then ' …