Vb函数返回null

mat*_*690 9 vb.net null

具有返回类型为整数的VB.net函数是否可以返回null?

Jar*_*Par 19

如果你严格地谈论一个空引用(C#的null版本)那么答案是否定的.在这里,dommer和Mitch都有正确的想法.您必须返回Nullable(OF Integer)才能传达值的绝对值.

但是,VB没有空值.相反,它使用Nothing.没有任何值表示值和引用类型的空值.它可以转换为任何值类型,只是表示C#中默认值(T)的等价物.在谈论VB时,很多人都说null,但实际上没什么意思.如果是这种情况则是,您可以从Integer返回函数返回Nothing

Public Function Example() As Integer
  Return Nothing
End Function
Run Code Online (Sandbox Code Playgroud)


dom*_*mer 8

你需要一个Nullable(Of Integer)的返回类型.