What is the difference between boolean and [boolean]?

I ran some code through an automatic translator for C # to VB, and he translated some code as follows:

Public Property Title As [String] 

How is this different from

 Public Property Title As String 

and why both exist?

+4
source share
3 answers

String is a keyword. If you want to use the keyword as an identifier, you will have to bracket it. [String] is an identifier. The String keyword always refers to the System.String class, and [String] can refer to your own class called String in the current namespace. Assuming you have an Imports System , they apply to the same thing most of the time, but may 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 main reason for the existence of [ ] for processing keywords as identifiers is compatibility with libraries from other languages ​​that can use VB keywords as type or member names.

+12
source

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

+1
source

In this example, they are not doing anything. (*) You can use parentheses to use reserved words as identifiers. For example: Dim [String] as String

EDIT: (*) If they have not defined their own class with the name [String] , that they can refer to

0
source

Source: https://habr.com/ru/post/1303223/


All Articles