在VB.Net,通常的方式来声明一个字符串将是:
In VB.Net, the usual way to declare a string would be :
Dim helloWorld As String = "Hello, World!"
不过,您也可以使用动态变量,如:
However, you can also use dynamic variables, such as :
Dim helloWorld = "Hello, World!"
无论最终会是同样的事情,但什么是最好的做法?
Both would end up to be the same thing, but what would be the best practice?
真的。 VB坐在净顶部和.Net的作品时,你最好坚持使用显式类型。唯一的例外是与选项推断
打开(现在是默认设置),你也声明类似于C#的变量 VAR
,或者如果你正在做的COM互操作或其他什么东西,真正需要一个动态类型...这是的非常的罕见的。
Really. VB sits on top of .Net, and .Net works best when you stick with explicit types. The only exceptions are with Option Infer
turned on (it is now by default) and you also declare variables similar to C#'s var
, or if you're doing COM interop or something else that truly requires a dynamic type... and that it is exceedingly rare.
上一篇:反序列化一个List<抽象类>与newtonsoft.json序列化、抽象类、List、json
下一篇:忽略XML序列化属性的属性使用XmlSerializer的.NET属性、序列化、XML、XmlSerializer