C# 到 VB.NET:**default** 关键字?
Possible Duplicate:
Default value for generics
OK, so while translating some code from C# to VB.NET, I came across the default keyword, and I'm simply replacing it with nothing.
Is this the proper way to do it, or is there a better "translation" for that keyword?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,那绝对没问题。虽然
Nothing
通常 意味着相当于 C# 的null
,但它可以与值类型一起使用,表示“那种类型”。Yup, that's absolutely fine. While
Nothing
is usually meant to mean the equivalent of C#'snull
, it can be used with value types to, to mean "the default value of that type".“default”用于泛型的上下文中,特别是当您不知道类型但仍希望拥有泛型类型的默认值的实例时。我不太擅长 Visual Basic,但我可以想象有一个等效的方法可以做同样的事情(?)。
有关 C# 中 default 关键字的用法示例,请参阅default 关键字在通用代码(C# 编程指南) (MSDN) 中:
"default" is used in the context of generics, especially when you do not know the type but still want to have an instance of the default value of the generic type. I am not very good at Visual Basic, but I can imagine there is an equivalent to do the same(?).
For an example of the usage of the default keyword in C#, see default Keyword in Generic Code (C# Programming Guide) (MSDN):