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

前端 未结 4 850
不思量自难忘°
不思量自难忘° 2021-01-12 02:40

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 \'|

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 03:07

    That would be the 'xor' operator. In your example code, it would toggle the Flags.Hidden either on or off, depending on the current value of x.Flags.

    The benefit of doing it this way is that it allows you to change the setting for Flags.Hidden without affecting any other flags that have been set.

提交回复
热议问题