473,386 Members | 1,973 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,386 software developers and data experts.

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 1339
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:bm**********@sulawesi-fi.lerc.nasa.gov...
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*******@nospam.mrdoc.cc> wrote in message
news:bm**********@sulawesi-fi.lerc.nasa.gov...
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**************@TK2MSFTNGP12.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*******************@SkPiAlMl.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**************@TK2MSFTNGP12.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.org> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:bm**********@sulawesi-fi.lerc.nasa.gov...
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.org> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
Console.WriteLine("The values of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);

--
William Stacey, DNS MVP

"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:bm**********@sulawesi-fi.lerc.nasa.gov...
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
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
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
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...
4
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?...
2
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...
1
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
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...
5
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.