What is VB's equivalent for C#'s default(T)
views:
319answers:
2
+6
A:
It's any of these:
Dim variable As T
Dim variable As T = Nothing
Dim variable As New T()
Assigning Nothing
event to value types is perfectly fine in VB.NET. And the latter is only possible if you specify either New
, or Structure
constraint for the generic type.
Anton Gogolev
2009-05-07 10:11:06
Reflector suggests using the following (but equivalent) line:Dim variable As T = CType(Nothing, T)
Matthew Steeples
2009-05-07 10:15:47
+1 to Dim variable as T = Nothing
Pondidum
2009-05-07 10:17:50
+1
A:
The closest equivalent to default(T) is really CType(Nothing, T) since it can be used in any context that default(T) is used (i.e. as an expression).
PaulV
2009-05-07 19:30:16