Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does [String] mean in VB.NET?

Tags:

vb.net

Does anybody know what does the following construct mean:

    Dim s1 as [String]

What do the square brackets mean? And why does the following statement with Integer fail while the one above, with String works?

    Dim i1 as [Integer]

Thanks in advance.

like image 595
Tudor Olariu Avatar asked Feb 04 '10 09:02

Tudor Olariu


2 Answers

THe square brackets is used so that the compiler interprets it as a type, even if it would be a keyword. Imagine for example if you had a class named As:

Dim a As [As]

This is usually only used in auto generated code, so that it works with any type that you throw at it.

The reason that you can't use [Integer] is that Integer is not a data type, it's a keyword. You would have to use the corresponding data type, i.e. [Int32].

like image 97
Guffa Avatar answered Oct 06 '22 15:10

Guffa


Square brackets are used to create a variable that has the same name as a keyword in VB.NET. So they are more often used that way:

Dim [Integer] As Integer
Dim [String] As String
like image 23
Darin Dimitrov Avatar answered Oct 06 '22 17:10

Darin Dimitrov