is it possible for a VB.net function with a return type of integer to return null ?
+1
A:
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.
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
Public Function Example() As Integer
Return Nothing
End Function
JaredPar
2009-04-03 13:36:43
So your Example() function returns the Integer 0, because VB casts Nothing to the default value for an Integer. To the caller, there's no difference between what you've written and return 0. Or am I wrong?
MarkJ
2009-04-04 10:13:48
@MarkJ, you are correct. There is discernible difference between return 0 and return Nothing.
JaredPar
2009-04-04 13:51:45