An open API service indexing awesome lists of open source software.

https://github.com/patridge/vb-default-tests

Confirming the various ways of doing C#'s default(T) in VB
https://github.com/patridge/vb-default-tests

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

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.