Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Flag enum
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01269641
Message ID:
01269745
Views:
8
>Hi,
>I am using [flag] enum to store combination of multiple value. How could I test if it contains certain value?
>
>Thank you

(you may know this, but just in case you don't) the [Flag] attribute isn't enough to make an enum addable (it changes the behavior of ToString()). You need to explicitly set the values, ex.
public enum Sample
{
   OptionOne = 1,
   OptionTwo = 2, 
   OptionThree = 4,
   OptionFour = 8
}
To determine which flags are set:
Sample sampleFlag = Sample.OptionTwo | Sample.OptionThree

if ((sampleFlag & Sample.OptionTwo) == Sample.OptionTwo)
   // Do something, OptionTwo is selected

if ((sampleFlag & Sample.OptionThree) == Sample.OptionThree)
   // Do something, OptionThree is selected
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Reply
Map
View

Click here to load this message in the networking platform