VB 等效于 C# 的默认值(T) [英] VB equivalent for C#'s default(T)
本文介绍了VB 等效于 C# 的默认值(T)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与 C# 的 default(T)
等效的 VB 是什么 - 默认运算符
What is VB's equivalent for C#'s default(T)
- the default operator
推荐答案
以下任意一种:
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
约束时才有可能.
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.
这篇关于VB 等效于 C# 的默认值(T)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文