|
-
Jun 2nd, 2006, 09:51 AM
#1
Thread Starter
Not NoteMe
[RESOLVED] [2.0] Iterating through an enumeration's possible values
I've got a Type variable that is an enumeration, although i don't know which one. Is there an easy of listing it's possible values, along with their names?
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 2nd, 2006, 07:24 PM
#2
Hyperactive Member
Re: [2.0] Iterating through an enumeration's possible values
 Originally Posted by SLH
I've got a Type variable that is an enumeration, although i don't know which one. Is there an easy of listing it's possible values, along with their names?
If we have a ennumeration variable, then we can easily show its possible values by writing the name of the enumeration variable and after that place dot(.) you will see it's possible values of that enumeration type varialbe.
Imran Ahmad Mughal
"Visual Studio .NET 2005/.NET Framework 2.0"
The eyes are the greatest telescopes, one will ever need to study the universe. Let the heart be the tripod, the mind be the shaft, then let the eyes become the lens of that great telescope of which God gave to us all.
-
Jun 2nd, 2006, 07:27 PM
#3
Re: [2.0] Iterating through an enumeration's possible values
 Originally Posted by ahmad_iam
If we have a ennumeration variable, then we can easily show its possible values by writing the name of the enumeration variable and after that place dot(.) you will see it's possible values of that enumeration type varialbe.
Imran Ahmad Mughal
That will give you the name of each enumeration... cast it to integer to get the values
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 3rd, 2006, 03:36 AM
#4
Re: [2.0] Iterating through an enumeration's possible values
Code:
foreach (string name in Enum.GetNames(typeof(MessageBoxButtons)))
{
MessageBox.Show("Name: " + name);
}
foreach (MessageBoxButtons value in Enum.GetValues(typeof(MessageBoxButtons)))
{
MessageBox.Show("Value (as string): " + value.ToString());
MessageBox.Show("Value (as int): " + (int)value);
}
-
Jun 3rd, 2006, 04:38 AM
#5
Thread Starter
Not NoteMe
Re: [2.0] Iterating through an enumeration's possible values
Thanks for the example, but what type is Enum?
I have my Type variable (which i know is an enum) which doesn't have a GetNames or a GetValues method.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 3rd, 2006, 06:28 AM
#6
Re: [2.0] Iterating through an enumeration's possible values
Enum IS the type. GetNames and GetValues are static methods of the Enum class. Notice that you pass the Type of your specific enumerated type to the method as a parameter. I've just used MessageBoxButtons as an example. You can pass your own enumerated Type instead.
-
Jun 3rd, 2006, 08:13 AM
#7
Thread Starter
Not NoteMe
Re: [2.0] Iterating through an enumeration's possible values
Ah ha, gottya. Didn't realise MessageBoxButtons was an enumeration!
Thanks for your help.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|