布尔值和[布尔值]有什么区别?

发布于 2024-08-24 04:06:36 字数 198 浏览 8 评论 0原文

我通过 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 技术交流群。

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

发布评论

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

评论(3

陌伤ぢ 2024-08-31 04:06:36

String 是一个关键字。如果您想使用关键字作为标识符,则必须将其括在方括号中。 [String] 是一个标识符。 String 关键字始终引用 System.String 类,而 [String] 可以引用您自己的名为 String 的类当前的命名空间。假设您有导入系统,大多数时候两者都指相同的事物,但它们可以不同:

Module Test
    Class [String]
    End Class
    Sub Main()
        Dim s As String = "Hello World"        // works
        Dim s2 As [String] = "Hello World"     // doesn't work
    End Sub
End Module

[] 将关键字视为标识符是为了与其他语言的库(可能使用 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 to System.String class while [String] can refer to your own class named String in the current namespace. Assuming you have Imports System, both refer to the same thing most of the time but they can be different:

Module Test
    Class [String]
    End Class
    Sub Main()
        Dim s As String = "Hello World"        // works
        Dim s2 As [String] = "Hello World"     // doesn't work
    End Sub
End Module

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.

夕色琉璃 2024-08-31 04:06:36

[] 允许您使用 VB 关键字作为标识符,就像 C# 中的 @ 一样。在这里没有用。

[] allows you to use VBs keywords as identifiers, just like @ in c#. it is useless here.

深海夜未眠 2024-08-31 04:06:36

在该示例中,它们不执行任何操作。(*) 不过,您可以使用括号将保留字用作标识符。例如: 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

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