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

Test an enum without converting to an array first

Is there a quick way to determine if a value is in an enum? Consider for example,
Expand|Select|Wrap|Line Numbers
  1. public enum GenderEnum
  2. {
  3.    Unknown = 0,
  4.    Male = 1,
  5.    Female = 2
  6. }
  7.  
  8. if (gender in GenderEnum) // THIS WILL NOT WORK!
  9. { blah blah} 
I don't want to convert to an array if possible, just check the enum and get a yes/no answer.
May 7 '13 #1
1 1164
vijay6
158 100+
Hey NewIsrael, try this code...

Expand|Select|Wrap|Line Numbers
  1. int gender = 2;
  2.  
  3. foreach (GenderEnum ge in Enum.GetValues(typeof(GenderEnum)))
  4. {
  5.     if((int)ge == gender)
  6.     {
  7.         MessageBox.Show("Found. Gender -> " + ge);
  8.     }
  9. }
May 7 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: dof | last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D #include stuff .... ...
2
by: Richard L Rosenheim | last post by:
I'm converting some routines from C to C#. The code involves having arrays of bytes which are passed to a function as an array of longs. Well, technically the C code has a pointer to an array of...
3
by: Pete Davis | last post by:
I've never done this in C# so I don't know what the appropriate way of doing it is. I've got an array of bytes and I need to convert the array into "usable" data. For example, the first 4 bytes...
5
by: shivaprasad | last post by:
Hi all, I am a Beginner to c#. I Need to convert array of byte data type to string. How to do this.. ex: byte bytes = new byte; this bytes get filled up. Now I need to convert to string.
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
11
by: monomaniac21 | last post by:
hi all is there a function to convert all values of array $row into seperate variables: $row = mysql_fetch_array($result); // i dont want to have to do this anymore :-) $name = $row;
1
by: jimmypringles | last post by:
Anyone knows how how to add "number" strings without converting them to integers? I came up with this function but it didn't work perfectly. e.g. I added "1998" and "8991" and the result was...
7
by: Travis | last post by:
Just curious, which takes less memory? enum Months { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; static const char *Months =
4
by: mahalingsalimath | last post by:
Sir i want to evualate an infix expression without converting into an intermediate form of postfix, using two stacks as a datastructures using C programming.
1
by: XuFyaN | last post by:
Hwo to create Rown and coloumn of Enumeration values i want to create a table of these values using 2Darray and print them using nested loop. enum Days {Mon, Tues, Wed, Thurs, Fri} enum...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.