Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Confirming the various ways of doing C#'s default(T) in VB
Visual Basic C#
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
DefaultWrapper
VbDefault
.gitignore
LICENSE
README.md
VbDefault.sln

README.md

VB-default-tests

Confirming the various ways of doing C#'s default(T) in VB are all equivalent.

Methods tested [using simple Debug.Assert on a command line app]:

Public Function GetDefaultDeclaration(Of T)() As T
    Dim result As T = Nothing
    Return result
End Function
Public Function GetDefaultNothingDirect(Of T)() As T
    Return Nothing
End Function
Public Function GetDefaultNothingCtype(Of T)() As T
    Return CType(Nothing, T)
End Function
Public Function GetDefaultNothingDirectCast(Of T)() As T
    Return DirectCast(Nothing, T)
End Function

Method not tested:

Return New T() ' Not equivalent to default(T) at all and only works for reference types.
Something went wrong with that request. Please try again.