By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,808 Members | 1,477 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,808 IT Pros & Developers. It's quick & easy.

Help with a Non-Escaped, Non-Redundant Brackets question?

P: 7
I'm not a really new programmer, but I'm still working on learning all of the .net things that I should know. So when I came across this one, I started to dig into it so see if I could figure it out...

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 14, 15, and 18 - "[Enum]"

Expand|Select|Wrap|Line Numbers
  1. Public Class ParseTest
  2.  
  3.     <FlagsAttribute()> _
  4.     Enum Colors
  5.         Red = 1
  6.         Green = 2
  7.         Blue = 4
  8.         Yellow = 8
  9.     End Enum
  10.  
  11.     Public Shared Sub Main()
  12.         Console.WriteLine("The entries of the Colors Enum are:")
  13.         Dim colorName As String
  14.         For Each colorName In [Enum].GetNames(GetType(Colors))
  15.             Console.WriteLine("{0}={1}", colorName, Convert.ToInt32([Enum].Parse(GetType(Colors), colorName)))
  16.         Next colorName
  17.         Console.WriteLine()
  18.         Dim myOrange As Colors = CType([Enum].Parse(GetType(Colors), "Red, Yellow"), Colors)
  19.         Console.WriteLine("The myOrange value {1} has the combined entries of {0}", myOrange, Convert.ToInt64(myOrange))
  20.     End Sub
  21. End Class
  22.  


(code is from http://msdn2.microsoft.com/en-us/library/essfb559.aspx)
Sep 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.