Here's what I know about brackets - If they are used around a reserved word then that becomes a usable (escaped) name (i.e. Dim [String] as Integer). If they are used around a type in a DIM or NEW type statement then they're redundant and actually go away (i.e. Dim MyString as [String]).
Here's my problem:
There is at least one time in the documentation where brackets aren't used for escaping, nor do they seem to be redundant (an error occurs if they aren't there), but I can't seem to find documentation to tell me why they ARE needed (I hate it when I don't know WHY I should do things)!
Can anyone give me a reference where this is explained? Thanks!
Here's the code (Straight from the VS2005 help doc)
Confusing piece is on lines 13, 14, and 18 - "[Enum]"
Expand|Select|Wrap|Line Numbers
- Public Class ParseTest
- Enum Colors
- Red = 1
- Green = 2
- Blue = 4
- Yellow = 8
- End Enum
- Public Shared Sub Main()
- Dim colorName As String
- Console.WriteLine("The entries of the Colors Enum are:")
- For Each colorName In [Enum].GetNames(GetType(Colors))
- Console.WriteLine("{0}={1}", colorName, Convert.ToInt32([Enum].Parse(GetType(Colors), colorName)))
- Next colorName
- Console.WriteLine()
- Dim myOrange As Colors = CType([Enum].Parse(GetType(Colors), "Red, Yellow"), Colors)
- Console.WriteLine("The myOrange value {1} has the combined entries of {0}", myOrange, Convert.ToInt64(myOrange))
- End Sub
- End Class