Yes, but why didn’t you just try it? And not only is it possible to write it, but it’s actually legal C#. It will assign the value of the boolean expression b == c
to the variable a
, which I’m assuming you declared, implicitly or explicitly, as bool
. Stylistically, I prefer to see
a = (b == c);
or
var a = (b == c);
or
bool a = (b == c);
I think these are easier to read than without the parentheses.
solved Is a = b == c possible to write in c#?