布尔值和[布尔值]有什么区别?
我通过 C# 到 VB 的自动翻译器运行了一些代码,它翻译了一些如下代码:
Public Property Title As [String]
这与两者有何不同
Public Property Title As String
?为什么两者都存在?
I ran some code through an automatic translator for C# to VB, and it translated some code like this:
Public Property Title As [String]
How is this different to
Public Property Title As String
and why do both exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
String
是一个关键字。如果您想使用关键字作为标识符,则必须将其括在方括号中。[String]
是一个标识符。String
关键字始终引用System.String
类,而[String]
可以引用您自己的名为String
的类当前的命名空间。假设您有导入系统
,大多数时候两者都指相同的事物,但它们可以不同:[] 将关键字视为标识符是为了与其他语言的库(可能使用 VB 关键字作为类型或成员名称)进行互操作。
String
is a keyword. If you want to use a keyword as an identifier, you'll have to enclose it in brackets.[String]
is an identifier.String
keyword always refers toSystem.String
class while[String]
can refer to your own class namedString
in the current namespace. Assuming you haveImports System
, both refer to the same thing most of the time but they can be different:The primary reason for existence of
[ ]
for treating keywords as identifiers is interoperability with libraries from other languages that may use VB keywords as type or member names.[] 允许您使用 VB 关键字作为标识符,就像 C# 中的 @ 一样。在这里没有用。
[] allows you to use VBs keywords as identifiers, just like @ in c#. it is useless here.
在该示例中,它们不执行任何操作。(*) 不过,您可以使用括号将保留字用作标识符。例如:
Dim [String] as String
编辑:
(*) 除非他们定义了自己可以引用的名为
[String]
的类In that example, they do nothing.(*) You can use brackets to use reserved words as identifiers, though. E.g.:
Dim [String] as String
EDIT:
(*) Unless they've defined their own class called
[String]
that they could be referring to