Referencing an Enum with Embedded Spaces

D

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 !!!
 
M

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.

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 !!!
 
H

Herfried K. Wagner [MVP]

Desmond Cassidy said:
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/>
 
D

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.


Herfried K. Wagner said:
Desmond Cassidy said:
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/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top