473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using brackets to describe root classes in VB.Net - maybe?

I posted this in the VB forum several days ago, and got no reply. Since it's specific to VB.Net I thought I'd try it here. I'm a relatively-experienced VB 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 13, 14, and 18 - "[Enum]"

Expand|Select|Wrap|Line Numbers
  1.   Public Class ParseTest
  2.    Enum Colors
  3.      Red = 1
  4.      Green = 2
  5.      Blue = 4
  6.      Yellow = 8
  7.    End Enum
  8.  
  9.    Public Shared Sub Main()
  10.       Dim colorName As String
  11.  
  12.       Console.WriteLine("The entries of the Colors Enum are:")
  13.       For Each colorName In [Enum].GetNames(GetType(Colors))
  14.          Console.WriteLine("{0}={1}", colorName, Convert.ToInt32([Enum].Parse(GetType(Colors), colorName)))
  15.       Next colorName
  16.       Console.WriteLine()
  17.  
  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 21 '07 #1
5 1440
Plater
7,872 Expert 4TB
It almost looks like they're used to specifuy a typecast to a custom object (i.e. the custom enum of Colors you just made)
Or it might be similar to the Me. (or this. if you're in C#) like you suggested?

Have you tried running the code without the brackets?
Sep 21 '07 #2
Have you tried running the code without the brackets?
Sort of. Removing them gets an "Expression Expected" error.
(An operator such as + or = requires an expression for its right operand, but no recognizable expression appears.Error ID: BC30201)

It almost looks like they're used to specify a typecast to a custom object (i.e. the custom enum of Colors you just made)Or it might be similar to the Me.
I thought that it might be a custom class that's part of System... Actually, I just tried "System.Enum" instead of [Enum]... that worked with no error. So... does the bracket then look for an underlying version of an object, or does it relate to an imported class or...?
Sep 21 '07 #3
Plater
7,872 Expert 4TB
Well i'm not sure, BUT I have always wondered if it was possible to itterate through an enum, so that looks pretty cool there.
Sep 21 '07 #4
Well I'm not sure, BUT I have always wondered if it was possible to iterate through an enum, so that looks pretty cool there.
Looks like you can!

I actually found the code in question while trying to help with an XML-ish text file save methodology I'm using to restore the value of an enum based on a text string. (e.g. the "Parse" function shown above.

I'll go under the assumption that the brackets are used to refer to an underlying imported class type that is also a keyword. (Unless someone else tells me different!)

Thanks!
Sep 21 '07 #5
Frinavale
9,735 Expert Mod 8TB
I'm looking into this more...it's something I don't know.
I just found out that if you type "enum" into the search function for the MSDN Library...it crashes...

But!
If you type [enum] for the search...
It doesn't crash

crazy...
Sep 21 '07 #6

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

Similar topics

6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
11
by: TGF | last post by:
I am wondering if it is feasible to use .NET for applications that have to be very fast. We have a few applications that are blazingly fast, written in Borland C++ using Borland C++ Builder. We...
2
by: sp | last post by:
Hello Everybody, I need to convert xml that we get from sqlserver For xml auto to my own xml format using asp.net classes. Any ideas and suggestions would be appreciated. Thanks in Advance sp
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
1
by: chidam.chidam | last post by:
Hi all, I would like to implement log4net for logging my application. First let me describe in short about the application. I have a solution with two exe file outputs and several dll assemblies....
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.