473,396 Members | 1,938 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.

How to iterate through a collection of enum values?

Greetings,

If I populate an ArrayList with values from, let's say, the Keys enum:

ArrayList a = new ArrayList();
a.Add(Keys.Home);
a.Add(Keys.End);

....then how do I iterate through the collection to see which values it
contains?

Thanks,
Billy
Nov 16 '05 #1
3 11893
Billy Porter wrote:
If I populate an ArrayList with values from, let's say, the Keys enum:

ArrayList a = new ArrayList();
a.Add(Keys.Home);
a.Add(Keys.End);

...then how do I iterate through the collection to see which values it
contains?


Hi Billy,

string[] allKeys = System.Enum.GetNames(Keys.GetType());
foreach (string s in allKeys)
{
Console.WriteLine(s);
}

Cheers

Arne Janning
Nov 16 '05 #2
Arne Janning wrote:
Billy Porter wrote:
If I populate an ArrayList with values from, let's say, the Keys enum:

ArrayList a = new ArrayList();
a.Add(Keys.Home);
a.Add(Keys.End);

...then how do I iterate through the collection to see which values it
contains?

Hi Billy,

string[] allKeys = System.Enum.GetNames(Keys.GetType());
foreach (string s in allKeys)
{
Console.WriteLine(s);
}

Cheers

Arne Janning


Or did you mean something else:

ArrayList al = new ArrayList();
al.Add(DialogResult.OK);
al.Add(DialogResult.No);

foreach (object o in al)
{
Console.WriteLine(System.Enum.Parse(DialogResult.G etType(),
o.ToString()).ToString());
}

Cheers

Arne Janning
Nov 16 '05 #3
Thanks!

"Arne Janning" <sp*****************@msn.com> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl...
Billy Porter wrote:
If I populate an ArrayList with values from, let's say, the Keys enum:

ArrayList a = new ArrayList();
a.Add(Keys.Home);
a.Add(Keys.End);

...then how do I iterate through the collection to see which values it
contains?


Hi Billy,

string[] allKeys = System.Enum.GetNames(Keys.GetType());
foreach (string s in allKeys)
{
Console.WriteLine(s);
}

Cheers

Arne Janning

Nov 16 '05 #4

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

Similar topics

2
by: Mark | last post by:
Assume you've declared an enum .... public enum MyEnum { First, Second, Third } Without knowing the values of the enum, is it possible to iterate through all the possible values...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
by: John A Grandy | last post by:
how to iterate through the members of an Enum ? Enum EnumAction None = 0 Action1 = 1 Action2 = 2 Action3 = 3 Action4 = 4 End Enum
2
by: Lee Gillie | last post by:
I see this was posted a long time ago, but it has since expired. Given.... Public Enum Fruit Apple Banana Cherry Peach Strawberry
11
by: Boni | last post by:
Dear all, following code iterates thru the hash table. Dim _Enumerator As IDictionaryEnumerator = _myhashtable.GetEnumerator While _Enumerator.MoveNext() ....
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
6
by: Steven Woody | last post by:
is there any way in C leting me iterate all integer constants in a enum type ? their values might not be continue. thanks. - woody
5
by: Lee | last post by:
When extending CollectionBase is it possible to sort on a particular field of each object in the collection? For example if I created a inherited class from CollectionBase and filled it with...
2
by: garth | last post by:
Hi, Is it possible to iterate over and enumerated type in C#? If so please can you paste a simple exampel up that covers the whole process. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.