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

Checking if enum type value contains certain value

Hello,

Is there some short-gand way to check if the enum type value contains
certain value?

Ie, the talk here is about Regex object:

Regex re = new Regex(@"pattern", RegexOptions.IgnoreCase |
RegexOptions.Multiline);
if ((re.Options & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase) ...
do stuff ...

This "if" expression is rather lengthy, perhaps there is some shorter way to
check wether the value contains one of the ORed enum values?

Thanks,

Pavils
Nov 16 '05 #1
2 3402
Pavils Jurjans <pa****@mailbox.riga.lv> wrote:
Is there some short-gand way to check if the enum type value contains
certain value?

Ie, the talk here is about Regex object:

Regex re = new Regex(@"pattern", RegexOptions.IgnoreCase |
RegexOptions.Multiline);
if ((re.Options & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase) ...
do stuff ...

This "if" expression is rather lengthy, perhaps there is some shorter way to
check wether the value contains one of the ORed enum values?


Well, you don't need to check for equality - just "non-zeroness":

if ((re.Options & RegexOptions.IgnoreCase) != 0)

which is fairly straightforward.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Yes, that's true!

I was not aware that runtime will implicitly convert enum type to int so
that it can be compared to zero.

Thanks!

Pavils.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Pavils Jurjans <pa****@mailbox.riga.lv> wrote:
Is there some short-gand way to check if the enum type value contains
certain value?

Ie, the talk here is about Regex object:

Regex re = new Regex(@"pattern", RegexOptions.IgnoreCase |
RegexOptions.Multiline);
if ((re.Options & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase) .... do stuff ...

This "if" expression is rather lengthy, perhaps there is some shorter way to check wether the value contains one of the ORed enum values?


Well, you don't need to check for equality - just "non-zeroness":

if ((re.Options & RegexOptions.IgnoreCase) != 0)

which is fairly straightforward.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

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

Similar topics

9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
2
by: MT | last post by:
Hi, I am currently validating an XML file against a Schema using XMLValidatingReader. The schema actually contains ranges for particular elements and I have been using it to detect range errors...
2
by: mrhicks | last post by:
Hello all, I have a question about enumerations. Within some requirements data passed back a certain bit field is defined by three bits then in another section the bit field is defined as 4...
18
by: Nebula | last post by:
Consider enum Side {Back,Front,Top,Bottom}; enum Side a; Now, why is a = 124; legal (well it really is an integer, but still, checking could be performed..) ? Wouldn't enums be more useful if...
1
by: Pavils Jurjans | last post by:
Hello, Is there some short-gand way to check if the enum type value contains certain value? Ie, the talk here is about Regex object: Regex re = new Regex(@"pattern", RegexOptions.IgnoreCase...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
5
by: Sin Jeong-hun | last post by:
Hello. This question may be stupid. enum MyValues { Value1, Value2, Value3, Value4, Value5 } ....in the code...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: 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...

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.