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 / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Evaluate Enum

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
iwdu15 - 29 Jun 2007 05:54 GMT
hi, im getting the powerstate of the battery
usingSystemInformation.PowerState like so:

PowerStatus power = SystemInformation.PowerStatus;

           if (power.BatteryChargeStatus == BatteryChargeStatus.Charging)
//code here

but the problem is, the enum is BatteryChargeState shows this during debug

        power.BatteryChargeStatus    High | Charging   

how can i write an if statement for that? ive tried

if (power.BatteryChargeStatus == BatteryChargeStatus.High |
BatteryChargeStatus.Charging)

but that didnt work....any help would be great! thanks

Signature

-iwdu15

Göran Andersson - 29 Jun 2007 06:03 GMT
> hi, im getting the powerstate of the battery
> usingSystemInformation.PowerState like so:
[quoted text clipped - 14 lines]
>
> but that didnt work....any help would be great! thanks

if ((power.BatteryChargeStatus & Charging) != 0)

Signature

Göran Andersson
_____
http://www.guffa.com

Ben Voigt [C++ MVP] - 29 Jun 2007 08:13 GMT
>> hi, im getting the powerstate of the battery
>> usingSystemInformation.PowerState like so:
[quoted text clipped - 16 lines]
>
> if ((power.BatteryChargeStatus & Charging) != 0)

maybe even better:

if ((power.BatteryChargeStatus & BatteryChargeStatus.Charging) ==
BatteryChargeStatus.Charging)
Göran Andersson - 29 Jun 2007 12:58 GMT
>>> hi, im getting the powerstate of the battery
>>> usingSystemInformation.PowerState like so:
[quoted text clipped - 21 lines]
> if ((power.BatteryChargeStatus & BatteryChargeStatus.Charging) ==
> BatteryChargeStatus.Charging)

Yes, that's useful if you want to match a composite enum value exactly.
For example:

[Flags]
enum Value { Some = 1, Other = 2, Any = 3}

if ((x & Value.Any) != ) {
   MessageBox.Show("some, other or both");
}
if ((x & Value.Any) == Value.Any) {
   MesssageBox.Show("both some and other");
}

:)

Signature

Göran Andersson
_____
http://www.guffa.com


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.