VB equivalent for C#'s default(T)

vb.netDefault Value

vb.net Problem Overview


What is VB's equivalent for C#'s default(T) - the default operator

vb.net Solutions


Solution 1 - vb.net

It's any of these:

Dim variable As T
Dim variable As T = Nothing
Dim variable As New T()
Dim variable As T = CType(Nothing, T) 'this is suggested by reflector

Assigning Nothing even 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.

Solution 2 - vb.net

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHathView Question on Stackoverflow
Solution 1 - vb.netAnton GogolevView Answer on Stackoverflow
Solution 2 - vb.netpanopticoncentralView Answer on Stackoverflow