vb.net Vb 函数返回空值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/713123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Vb Function returning null
提问by mat690
is it possible for a VB.net function with a return type of integer to return null ?
返回类型为整数的 VB.net 函数是否有可能返回 null ?
采纳答案by dommer
You'll need a return type of Nullable(Of Integer).
您将需要 Nullable(Of Integer) 的返回类型。
回答by JaredPar
If you're strictly talking about a null reference (C#'s version of null) then the answer is No. Both dommer and Mitch have the right idea here. You would have to return a Nullable(OF Integer) in order to communicate the abscence of a value.
如果您严格地谈论空引用(C# 的空引用),那么答案是否定的。dommer 和 Mitch 在这里都有正确的想法。您必须返回 Nullable(OF Integer) 才能传达值的缺失。
However, VB doesn't have a null value. Instead it uses Nothing. Nothing represents the empty value for both value and reference types. It is convertible to any value type and simply represents the equivalent of default(T) in C#. Many people say null when talking about VB but really mean Nothing. If this is the case then yes, you can return Nothing from an Integer returning function
但是,VB 没有空值。相反,它使用 Nothing。Nothing 表示值和引用类型的空值。它可以转换为任何值类型,并且仅表示 C# 中 default(T) 的等效项。许多人在谈论 VB 时都说 null,但实际上没有任何意义。如果是这种情况,那么是的,您可以从 Integer 返回函数中返回 Nothing
Public Function Example() As Integer
Return Nothing
End Function
回答by Mitch Wheat
Only if it is defined as returning a nullable integer.
仅当它被定义为返回一个可为空的整数时。