Dim s As String 和 Dim s As [String] 有什么区别?
有什么区别:
Dim s As String
和
Dim s As [String]
What is the difference between:
Dim s As String
and
Dim s As [String]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有什么区别。
在 VB 中,您可以将标识符括在方括号中,以强制将其解析为标识符而不是关键字。
例如,您可以编写
没有任何语法错误的内容。
括号除了指示标识符不是关键字之外没有任何作用,因此
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
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.它们是完全相同的东西。当您将括号放在类型名称周围时,它不会做任何不同的事情,但是当将括号放在标识符周围时,它允许您使用保留关键字。
所以这是合法的:
因为标识符名称周围的括号允许编译器知道您打算使用保留关键字。
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:
because the brackets around the identifier name allow the compiler to know you meant to use a reserved keyword.
发布的代码没有功能差异。
您可以使用方括号来声明与 VB.NET 关键字同名的变量。给定一个名为“Loop”的变量(VB 中的保留关键字):
此示例来自 有关该主题的 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):
This example is from MSDN's page on the topic.
从技术上讲没有区别。
Dim s As String
与Dim s As [String]
相同Technically there is no difference.
Dim s As String
is same asDim s As [String]