VB equivalent for C#'s default(T)

后端 未结 2 1987
后悔当初
后悔当初 2021-02-01 12:39

What is VB\'s equivalent for C#\'s default(T)

2条回答
  •  臣服心动
    2021-02-01 13:15

    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.

提交回复
热议问题