什么是VB对C#的default(T)
的等价物-- default operator
发布于 2009-05-07 02:11:07
可以是以下任意一种:
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
在VB.NET中,将Nothing
甚至赋给值类型是完全可以的,而后者只有在为泛型类型指定New
或Structure
约束时才有可能。
发布于 2009-05-07 11:30:16
与default(T)
最接近的等价物实际上是CType(Nothing, T)
,因为它可以在任何使用default(T)
的上下文中使用(即作为表达式)。
https://stackoverflow.com/questions/833791
复制相似问题