What is the difference between:
Dim s As String
and
Dim s As [String]
What is the difference between:
Dim s As String
and
Dim s 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.
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.
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.