If I execute the following statement:
dim defaultDate as Date = Nothing
defaultDate
contains the default value of the Date
structure
I suspect there is a clean way to retreive this value, like some kind of buitin constant, but i was not able to find it.
Q: What is the clean way to retrieve the default value of a given structure in VB.net ?
As you have already found, Nothing
is the correct way to do this in VB.NET for value types.
C# has a more "explicit" way of doing that with default(T)
.
The default Date
is Date.MinValue
.
0:00:00 (midnight) on January 1, 0001.
Dim d As Date = Nothing
If d = Date.MinValue Then
' yes, we are really here '
End If
I usually prefer Date.MinValue
instead of Nothing
, but i assume that's a matter of taste.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.