Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2008

Tip: Looking for answers? Try searching our database.

enums bitwise values.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ibrahim. - 19 Mar 2008 17:18 GMT
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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.