473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recurse through members of an enum

What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo
Nov 15 '05 #1
6 1346
Console.WriteLi ne("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(t ypeof(Colors)))
Console.WriteLi ne(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nosp am.mrdoc.cc> wrote in message
news:bm******** **@sulawesi-fi.lerc.nasa.go v...
What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo

Nov 15 '05 #2
I don't think this is possible since an enum is a type. You can iterate thru
collections which implement ienumerable, but an enum is not a collection.

"Laszlo Szijarto" <ls*******@nosp am.mrdoc.cc> wrote in message
news:bm******** **@sulawesi-fi.lerc.nasa.go v...
What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo

Nov 15 '05 #3
"Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote
in news:uL******** ******@TK2MSFTN GP12.phx.gbl:
I don't think this is possible since an enum is a type. You can
iterate thru collections which implement ienumerable, but an enum is
not a collection.


You can do this type of operation with Reflection... see previous post
replies for some specific code that demonstrates it.

-mbray
Nov 15 '05 #4
Thanks
"Michael Bray" <mb************ *******@SkPiAlM l.ctiusa.com> wrote in message
news:Xn******** *************** ********@207.46 .248.16...
"Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote
in news:uL******** ******@TK2MSFTN GP12.phx.gbl:
I don't think this is possible since an enum is a type. You can
iterate thru collections which implement ienumerable, but an enum is
not a collection.


You can do this type of operation with Reflection... see previous post
replies for some specific code that demonstrates it.

-mbray

Nov 15 '05 #5
sweet code william. sweet code
"William Stacey" <st*****@mvps.o rg> wrote in message
news:uU******** ******@tk2msftn gp13.phx.gbl...
Console.WriteLi ne("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(t ypeof(Colors)))
Console.WriteLi ne(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nosp am.mrdoc.cc> wrote in message
news:bm******** **@sulawesi-fi.lerc.nasa.go v...
What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo


Nov 15 '05 #6
Thank you. This is what I needed. Thank you all for your replies.
"William Stacey" <st*****@mvps.o rg> wrote in message
news:uU******** ******@tk2msftn gp13.phx.gbl...
Console.WriteLi ne("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(t ypeof(Colors)))
Console.WriteLi ne(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nosp am.mrdoc.cc> wrote in message
news:bm******** **@sulawesi-fi.lerc.nasa.go v...
What's the best way to recurse through the members of an enum?

I want to take an enum and dump into a ListBox the enum's names.

Thank you,
Laszlo


Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1787
by: Jason Heyes | last post by:
I know I can do this with an enum like this: enum { a, b, c, d }; int x = a + b + c + d; But what about this one? enum X { a, b, c, d }; int x = a + b + c + d; // will this compile?
1
2339
by: Old Wolf | last post by:
I tried this code: #include <iostream> #include <string> template<typename T> struct enum_properties { static const long max; static const std::string name;
21
6327
by: Bilgehan.Balban | last post by:
Hi, I have two different enum definitions with members of same name. The compiler complains about duplicate definitions. Is this expected behaviour? Can't I have same-named fields in different enum definitions? I think it should have been perfectly valid to do that. Its a stupid limitation to have to define disjoint enum symbol...
4
6477
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent? Thanks in advance... -Nikhil
2
1097
by: Dmitri Shvetsov | last post by:
Hi, Does anybody know if I can use something like recurse to get the whole list of the public members of the class and their types/values? For example, I created the object with default values, then I need to get another object, created somewhere else, for example by serialization method, then to assign all values from this external...
1
1343
by: Samuel Shulman | last post by:
I can't remember what is the namespace/class that can be used to retrieve all the members of an enum Thank you, Samuel
2
9208
by: Jay | last post by:
I have a few enums, a shortened example of one is: enum ParamTest {Err, Start, Block, Hold} Is there a programmatic way to find the number of "members" (probably the wrong C# term) of the Enum - this is 4 for the example given. One not very good way that I currently use is to add a dummy "LENGTH" member on the end: enum ParamTest...
5
4874
by: Paul | last post by:
VB.NET - VS 2005 Is it possible to create an Enum with numeric members. Example: Public Enum NumberOfDecimalPlaces Auto 1 2 3 4
4
8658
by: Samantha | last post by:
Hi - I am seeing enum members being used, with just the member's name, and not the enum name. for example: typedef enum Fruit { Apple = 0, Orange, Banana = 0xFF
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.