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
- Host: GitHub
- URL: https://github.com/patridge/vb-default-tests
- Owner: patridge
- License: mit
- Created: 2012-04-20T16:58:07.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2014-07-02T16:18:44.000Z (almost 11 years ago)
- Last Synced: 2025-01-01T10:25:29.138Z (5 months ago)
- Language: Visual Basic
- Size: 156 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.