VB.net函数不返回任何内容,但在比较过程中抛出错误



在我们的代码库中,有一个函数应该返回一个对象或什么都不返回。

确切的代码是:

Return Nothing

调用方法看起来像这个

myObj = theClass.function()
if myObj <> nothing then // fails

我在C#中遗漏了什么吗?我会使用if not null检查,为什么在VB.net中会失败,我如何检查func的返回val是否为空?

提前感谢

为了比较引用(和Nothing),需要使用IsIsNot,而不是=<>

即:

If myObj IsNot Nothing Then ' …

最新更新