[Solved] Bitwise operations | And | Which situation is true or false in c#


In C# you write it like so:

bool b = (flag & a) != 0;

You can’t assign an int to a bool in C#, like you can in C++.

(In C++ the compiler generates code that effectively does the same as the code above, although most C++ compilers will generate a warning if you just try to assign an int to a bool.)

Also see the Visual C++ warning C4800, which tells you to write it this way in C++ too.

solved Bitwise operations | And | Which situation is true or false in c#