开发者

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]


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.


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'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.


Technically there is no difference. Dim s As String is same as Dim s As [String]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜