How do you used Flags Attribute

  • Thread starter Thread starter Patrick Blackman
  • Start date Start date
P

Patrick Blackman

Need example of how to use the flags attribute and to determine which flags
were set.
 
I don't know about a flags attribute, but using flags shouldn't be a
problem.

bool flag = false;

if (......)
flag = true;



if(flag == true)
// DO SOMETHING
 
[Flags]
enum ActionAttributes {
Read = 1,
Write = 2,
Delete = 4,
Query = 8,
Sync = 16
}

This is how you define an enumerated type with the FlagsAttribute

To assign e.g. ActionAttributes aa = ActionAttributes.Read |
ActionAttributes.Write;

To check if aa has the Read Attribute e.g. if ( (aa &&
ActionAttributes.Read) == ActionAttributes.Read) {}
 
Back
Top