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.
Herfried K. Wagner [MVP] - 19 Mar 2008 22:39 GMT
"Ibrahim." <Ibrahim@discussions.microsoft.com> schrieb:
> I have a enum structure like this ;
>
[quoted text clipped - 13 lines]
>
> 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;
///

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Jeff Johnson - 24 Mar 2008 22:25 GMT
> I have a enum structure like this ;
>
[quoted text clipped - 15 lines]
>
> now i want to get the enum values from daysSelected again ?
Are you saying you want to TEST the value to see if a certain day is in
there (easy, Herf gave you the code) or do you want to get the enum NAMES
back out of the value, e.g., given 33 do you want to get "Fri" and "Sun"
from it? The second part is a little more complicated, but possible.
BlackWasp - 24 Mar 2008 22:38 GMT
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.

Signature
BlackWasp
www.blackwasp.co.uk
> Hello,
>
[quoted text clipped - 19 lines]
>
> thanks.