Discussions Search    Reviews    Search Aid    Buzzzz    Google@Omgili Add to iGoogle   Bookmark and Share

  Advanced Search



How to compare enums?

On Thu, 3 Jul 2008 00:57:12 -0700 (PDT), nomad <...@btinternet.com

Hi,

I have an enum which obviously has several values. I want to be able
to do a comparison to see if the value selected by a user is the same
as one of the enums in the list. My code is below.

if (risk.Vehicle.ImmobiliserMake != ImmobiliserMake.None ||
risk.Vehicle.ImmobiliserMake != ImmobiliserMake.NA)

Although the risk.Vehicle.ImmobiliserMake is equal to None, it still
gioes into my if block. Any ideas where I am going wrong?

Appreciate the help.

 Latest discussions from this group  (microsoft.public.dotnet.languages.csharp)

Re: Problem extending Object  
[28 Aug 2008]
On 28 Aug 2008 00:44:57 GMT, J. Moreno <planb@newsreader s.com Since nobody seems to know...
know the answer in the vb group, guess I'll ask here... Does anyone know why I would be able...
No image in firefox  
[27 Aug 2008]
On Wed, 27 Aug 2008 06:31:00 -0700, Rui Oliveira <RuiOliveira@disc ussions.microsoft.co m...
I have the following code to show an image in html: "   :.. <img src=\"...
XXXBindingSource  
[27 Aug 2008]
On Wed, 27 Aug 2008 14:33:13 +0200, "Tony Johansson" <johansson.anders son@telia.com Hello...
Hello! What purpose does this object have ? //Tony
More...


On Thu, 3 Jul 2008 01:02:44 -0700 (PDT), "Jon Skeet [C# MVP]" <...@pobox.com

On Jul 3, 8:57 am, nomad <...@btinternet.com
Look carefully at your logic. You've said if it's not "none" *or* it's
not "NA", then go into the block. In other words, it would have to be
*both* "none" and "NA" to skip the block.

Basically you want to change || to &&.

Jon

On Thu, 3 Jul 2008 01:24:02 -0700 (PDT), nomad <...@btinternet.com

On 3 Jul, 09:02, "Jon Skeet [C# MVP]" <...@pobox.com
Thanks Jon, that did the trick.

Discussion Title: How to compare enums?
Title Keywords: compare  enums?