On 3 Jul, 09:02, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
> On Jul 3, 8:57*am, nomad <d.bedg...@btinternet.com> wrote:
>
> > 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?
>
> 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
Thanks Jon, that did the trick.
|