Dim s As String 和 Dim s As [String] 有什么区别?

发布于 2024-08-29 08:07:46 字数 109 浏览 6 评论 0原文

有什么区别:

Dim s As String

Dim s As [String]

What is the difference between:

Dim s As String

and

Dim s As [String]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一身骄傲 2024-09-05 08:07:46

没有什么区别。

在 VB 中,您可以将标识符括在方括号中,以强制将其解析为标识符而不是关键字。

例如,您可以编写

Dim [If], [As], [Dim]

没有任何语法错误的内容。

括号除了指示标识符不是关键字之外没有任何作用,因此 someVar[someVar] 是相同的。

There is no difference.

In VB, you can wrap an identifier in brackets to force it to be parsed as an identifier and not a keyword.

For example, you can write

Dim [If], [As], [Dim]

without any syntax errors.

The brackets have no effect other than indicating that the identifier isn't a keyword, so someVar and [someVar] are identical.

鲸落 2024-09-05 08:07:46

它们是完全相同的东西。当您将括号放在类型名称周围时,它不会做任何不同的事情,但是当将括号放在标识符周围时,它允许您使用保留关键字。

所以这是合法的:

Dim [String] as String

因为标识符名称周围的括号允许编译器知道您打算使用保留关键字。

They are the same exact thing. When you put brackets around the type name it doesn't do anything different but when the brackets are placed around an identifier it allows you to use a reserved keyword.

So this would be legal:

Dim [String] as String

because the brackets around the identifier name allow the compiler to know you meant to use a reserved keyword.

旧梦荧光笔 2024-09-05 08:07:46

发布的代码没有功能差异。

您可以使用方括号来声明与 VB.NET 关键字同名的变量。给定一个名为“Loop”的变量(VB 中的保留关键字):

Loop.Visible   = True  ' Causes an error.
[Loop].Visible = True  ' Sets the Visible property of the variable named "Loop".

此示例来自 有关该主题的 MSDN 页面

There's no functional difference in the code posted.

You can use square brackets to declare a variable with the same name as a VB.NET keyword. Given a variable named "Loop" (a reserved keyword in VB):

Loop.Visible   = True  ' Causes an error.
[Loop].Visible = True  ' Sets the Visible property of the variable named "Loop".

This example is from MSDN's page on the topic.

§普罗旺斯的薰衣草 2024-09-05 08:07:46

从技术上讲没有区别。 Dim s As StringDim s As [String] 相同

Technically there is no difference. Dim s As String is same as Dim s As [String]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文