Home All Groups Group Topic Archive Search About

Referencing an Enum with Embedded Spaces

Author
10 Sep 2006 4:24 PM
Desmond Cassidy
I created an Enum with the EnumBuilder which allows you to add items with spaces embedded as well as the name of the Enum. e.g. US States and a member of New York

The normal way you would iterate through an Enum  is as follows
For Each lstrItem As String In [Enum].GetNames(GetType(Geographical.US_States))

    Me.Combo.Items.Add(lstrItem)

Next

But how would you reference an Enum of "US States" ??? * Iknow I could just as easily create an Enum US_States...

just a question though !!!

Author
10 Sep 2006 8:39 PM
Michael D. Ober
You don't.  Even if the VB.NET syntax allows this, it would be extremely
confusing to programmers attempting to use or modify your Enum.

Mike Ober.

"Desmond Cassidy" <Desmond.Cass***@T-Online.de> wrote in message
news:eKIkgVP1GHA.3752@TK2MSFTNGP02.phx.gbl...
I created an Enum with the EnumBuilder which allows you to add items with
spaces embedded as well as the name of the Enum. e.g. US States and a member
of New York

The normal way you would iterate through an Enum  is as follows
For Each lstrItem As String In
[Enum].GetNames(GetType(Geographical.US_States))
    Me.Combo.Items.Add(lstrItem)
Next
But how would you reference an Enum of "US States" ??? * Iknow I could just
as easily create an Enum US_States...
just a question though !!!
Author
10 Sep 2006 9:44 PM
Herfried K. Wagner [MVP]
"Desmond Cassidy" <Desmond.Cass***@T-Online.de> schrieb:
>I created an Enum with the EnumBuilder which allows you to add items with
>spaces embedded as well as the name of the Enum. e.g. US States and a
>member of New York
>
>The normal way you would iterate through an Enum  is as follows
>For Each lstrItem As String In
>[Enum].GetNames(GetType(Geographical.US_States))
>    Me.Combo.Items.Add(lstrItem)
>Next
>
>But how would you reference an Enum of "US States" ??? * Iknow I could just
>as easily create an Enum US_States...

I'd choose a different approach:

Adding descriptions to enumeration constants
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=enumdescription&lang=en>

Creating enumerations of items with a certain arbitrary data type
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en>

Article in German:

<URL:http://dotnet.mvps.org/dotnet/articles/enums/>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
10 Sep 2006 10:03 PM
Desmond Cassidy
Absolutely excellent approach - Vielen Dank Herfried

Mike: The point was that I wanted to make the enum full data e.g. "New York"
, available for the combobox but not necessarily having the programmer
accessing it - the approach in Herfried suggestion is spot on !!

Many thanks,

Desmond.


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:%23sE%23OJS1GHA.4228@TK2MSFTNGP06.phx.gbl...
> "Desmond Cassidy" <Desmond.Cass***@T-Online.de> schrieb:
>>I created an Enum with the EnumBuilder which allows you to add items with
>>spaces embedded as well as the name of the Enum. e.g. US States and a
>>member of New York
>>
>>The normal way you would iterate through an Enum  is as follows
>>For Each lstrItem As String In
>>[Enum].GetNames(GetType(Geographical.US_States))
>>    Me.Combo.Items.Add(lstrItem)
>>Next
>>
>>But how would you reference an Enum of "US States" ??? * Iknow I could
>>just as easily create an Enum US_States...
>
> I'd choose a different approach:
>
> Adding descriptions to enumeration constants
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=enumdescription&lang=en>
>
> Creating enumerations of items with a certain arbitrary data type
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=anytypeenums&lang=en>
>
> Article in German:
>
> <URL:http://dotnet.mvps.org/dotnet/articles/enums/>
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>