.net – 在Visual Basic关键字(例如`String`)上使用CLR类型(例如`System.String`或`[String]`)是否有任何可以想象的优势?

我们都知道,在C#中,无论使用String(CLR类)还是字符串(C#关键字)都没有任何区别.有关详细信息,请参阅以下问题

> What is the difference between String and string in C#?

到目前为止,我的印象是VB.NET也是如此. language specification甚至说(强调我的):

The primitive types are identified through keywords,which are aliases for predefined types in the System namespace. A primitive type is completely indistinguishable from the type it aliases: writing the reserved word Byte is exactly the same as writing System.Byte.

因此,我非常惊讶地看到Visual Studio 2015有所不同:Visual Studio允许您指定框架名称(Int32 / Int64 / DateTime / …)的首选项(工具/选项/文本编辑器/基本/代码样式)原生VB关键字(整数/长/日/ …).

问题是:一旦告诉Visual Studio您更喜欢Framework名称,自动生成的代码使用[String](使用[] VB关键字转义,类似于C#的@)而不是String(对象,单一和所有相同) VB关键字与Framework类型名称匹配的其他类型).我认为这是错误的(并已提交了Connect issue),因为括号使代码混乱,并且如上所示,无论您使用[String](由于VB的自动系统导入有效地引用System.String),它都不会产生语义差异)或String(VB关键字别名System.String).

但是,由于Visual Studio开发人员非常聪明,所以我完全有可能忽略了某些东西,并且使用[String]而不是String实际上是有意义的,因此我的问题是:

在Visual Basic中使用[String]而不是String是否有任何可以想象的优势,或者Visual Studio编辑器只是“做错了什么”并且无用地混乱自动生成的代码?

解决方法

我认为使用String(指(1))会比[String]更连续.在整个地方使用[String]只是在VB的语法颜色上看起来不太好,因为它看起来像普通类型而不是关键字.我认为,当用VB语法着色时,除了它的外观之外,在代码中使用[String]而不是String是没有可能的优势.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...