Search code examples
c#arrays.netenumsxor

How to show logical and after that xor in C#


I am a beginner so please take it easy on me.

I wrote this code: ((x.Tags ?? 0) & byteFlags)) ^ (byteFlags) > 0)
x.tags is long data type
(long)byteFlagEnum.somethings & (long)byteFlagEnum.thing;

there is structure of byteFlagEnum </br />

public enum HotelBookTag : long
{
    .... = 1 << 0,
    ... = 1 << 1,
    ....  = 1 << 2,
    ..... = 1 << 3,
    thing = 1 << 4,
    somethings = 1 << 5,
}

but it givse me this error

Operator '^' cannot be applied to operands of type 'long' and 'bool'


Solution

  • It's probably your parentheses - causing the compiler to evaluate byteFlags > 0 to a bool first before the bitwise operations. Can you try:

        (((x.Tags ?? 0) & byteFlags) ^ (byteFlags)) > 0)