Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '^' do in c# (Enums)?

I was reading some 3rd party code and I found this:

x.Flags = x.Flags ^ Flags.Hidden;

What does it do?

I've used '&' and '|' for bitwise 'and' and 'or' with enums, but it's the first time I see the that symbol...

like image 601
juan Avatar asked Oct 24 '08 18:10

juan


People also ask

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.

What is -= in C?

-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A.

What is && operator in C?

The && (logical AND) operator indicates whether both operands are true. If both operands have nonzero values, the result has the value 1 . Otherwise, the result has the value 0 . The type of the result is int . Both operands must have an arithmetic or pointer type.


1 Answers

^ is the bitwise XOR operator in C#.

EDIT: a ^ b returns true if a is true and b is false or if a is false and b is true, but not both.

like image 147
Romain Verdier Avatar answered Sep 30 '22 19:09

Romain Verdier