Bitwise And in C#

I need to translate a similar line of code -

if (a & b) 
{

}

Where a is an int, b is a number from enum.

In C++, there is a "bitwise And"operator. Is it possible to do this in C#?

Author: gbg, 2016-01-26

1 answers

Easily.
In C#, as in C++, the operator & is responsible for the bitwise and.
Your example will look like this.

If a and b have the same meaningful type (for example, int, or some enum):

if ((a & b) != 0) {

}

If b has a type of any enum:

if ((a & (int)b) != 0) {

}
 7
Author: Dmitry D., 2016-01-26 02:39:51