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.
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]
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With