The && operator cannot be applied

I am testing a sample fragment that I found as an answer to another question

However, the compiler spits out this "Operator && cannot be applied to operands of type long and bool". Why is he doing this? When I read the code, it says: "If the mask and resolution are greater than 0 return success bool"

Am I reading this wrong?

(Also, no one called it a bad example, so I expected it to work. Not that I was an encoder to copy).

bool CheckMask( long Mask, long TestPermission ) {
    return Mask && TestPermission > 0;
}

long mask = 4611686844973976575;

const long MASK_ViewListItems = 0x0000000000000001;
bool HasPermission_ViewListItems = CheckMask(mask, MASK_ViewListItems);
// HasPermission_ViewListItems is true

const long MASK_UseClientIntegration = 0x0000001000000000;
bool HasPermission_UseClientIntegration = CheckMask(mask, MASK_UseClientIntegration);
// HasPermission_UseClientIntegration is false

There are a lot of similar questions in StackOverflow, and I clicked through most of them, there is a large list to my right. No one applied my situation, at least I managed to see the connection between the answers and my problem.

+5
2

&& ( AND, bool) & ( , bool ) - , , - . , .NET , - :

static bool CheckMask(long mask, long testPermission)
{
    return (mask & testPermission) > 0;
}

long:

[Flags]
public enum Permissions
{
    ViewListItems = 1 << 0,
    ...
    UseClientIntegration = 1 << 9
}

static bool CheckMask(Permissions mask, Permissions testPermission)
{
    return (mask & testPermission) != 0;
}
+12

, , :

(Mask & TestPermission) != 0

, :

  • & ( &&, bool)
  • , , - , ( != >).
+3

All Articles