enums bitwise values.

  • Thread starter Thread starter Ibrahim.
  • Start date Start date
I

Ibrahim.

Hello,

I have a enum structure like this ;

[Flags]
public enum days
{
Sun=1,
Mon=2,
Tue=4,
Wed=8,
Thur=16,
Fri=32,
Sat=64
}

now i sum only sun & fri & save to database table field

int daysSelected = (int) days.sun | days.fri

now i want to get the enum values from daysSelected again ?

thanks.
 
Ibrahim. said:
I have a enum structure like this ;

[Flags]
public enum days
{
Sun=1,
Mon=2,
Tue=4,
Wed=8,
Thur=16,
Fri=32,
Sat=64
}

now i sum only sun & fri & save to database table field

int daysSelected = (int) days.sun | days.fri

=> 'days daysselected = days.sun | days.fri;'
now i want to get the enum values from daysSelected again ?

\\\
bool sunset = (daysselected & days.sun) != 0;
///
 
If I understand you correctly, you want to change the integer back to an
enumeration value (or combination)?

If so, just cast the integer:

days selected = (days)daysSelected;

If you output this as a string it will be comma-separated. Check out
http://www.blackwasp.co.uk/FlagsAttribute.aspx for details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top