C# to VB.NET: the **default** keyword? [duplicate]

夙愿已清 提交于 2019-12-21 07:02:17

问题


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?


回答1:


Yup, that's absolutely fine. While Nothing is usually meant to mean the equivalent of C#'s null, it can be used with value types to, to mean "the default value of that type".




回答2:


"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):



来源:https://stackoverflow.com/questions/5922803/c-sharp-to-vb-net-the-default-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!