VB.net函数什么都不返回,但在比较期间抛出错误?

JL.*_*JL. 1 vb.net

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

确切的代码是这样的:

Return Nothing
Run Code Online (Sandbox Code Playgroud)

调用方法看起来像这样

myObj = theClass.function()

if myObj <> nothing then // fails
Run Code Online (Sandbox Code Playgroud)

我在C#中遗漏了一些东西我会使用if not null检查,为什么这会在VB.net中失败,我如何检查func的返回值是什么?

提前致谢

Kon*_*lph 5

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

那是:

If myObj IsNot Nothing Then ' …
Run Code Online (Sandbox Code Playgroud)