Anyway here’s my problem I have been modifying a whole C++ program to work in C# and I am pretty much done, I have this If statement in the C++ program.
if(info[i].location & 0x8 ||
info[i].location & 0x100||
info[i].location & 0x200)
{
//do work
}
else
{
return
}
And of course when I do this in C# it gives me a "Operator ‘||’ cannot be applied to operands of type ‘int’ and ‘int’" error.
Any clue on what my problem is, Im guessing that C# has got a way of doing this as I am fairly unfamiliar with these old C operators.
Why it fails
Fundamentally it’s the same difference as this:
vs
Basically C# is a lot stricter when it comes to logical operators and conditions – it forces you to have use something which is either
boolor convertible tobool.As an aside, that’s also why in C# this isn’t just a warning, but a full-blown error:
If you see comparisons this way round:
That’s usually developers trying to avoid typos like the above – but it’s not needed in C# unless you’re really comparing against constant
boolvalues.Fixing the problem
I suspect you just need:
It’s possible that you don’t need all of those brackets… but another alternative is just to use one test:
After all, you’re just testing whether any of those three bits are set…
You should also consider using a flags-based enum:
Then you could use:
Or using Unconstrained Melody: