在Visual Basic中,如何将关键字String映射为CLR类型System.String或[String]?

2026-05-06 13:341阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计501个文字,预计阅读时间需要3分钟。

在Visual Basic中,如何将关键字String映射为CLR类型System.String或[String]?

我们深知,在C语言中,数组是一种基本的数据结构。下面是一个简单的数组使用示例:

c#include

int main() { int numbers[5]={1, 2, 3, 4, 5}; int sum=0;

for (int i=0; i <5; i++) { sum +=numbers[i]; }

printf(数组的总和是:%d\n, sum);

return 0;}

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

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

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

在Visual Basic中,如何将关键字String映射为CLR类型System.String或[String]?

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是没有可能的优势.

本文共计501个文字,预计阅读时间需要3分钟。

在Visual Basic中,如何将关键字String映射为CLR类型System.String或[String]?

我们深知,在C语言中,数组是一种基本的数据结构。下面是一个简单的数组使用示例:

c#include

int main() { int numbers[5]={1, 2, 3, 4, 5}; int sum=0;

for (int i=0; i <5; i++) { sum +=numbers[i]; }

printf(数组的总和是:%d\n, sum);

return 0;}

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

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

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

在Visual Basic中,如何将关键字String映射为CLR类型System.String或[String]?

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是没有可能的优势.