PDA

View Full Version : c# ~()


Consort
2nd Jun 2012, 7:36 PM
Came across this line
bool succeeded = this.DoLoop(~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached), new InteractionInstance.InsideLoopFunction(this.NapLoop), null);

Could someone explain the ~ to me?
I tried but it's pretty hard to google this :)

Buzzler
2nd Jun 2012, 8:06 PM
~ is bitewise complement. Pretty much like the ! for boolean.

http://msdn.microsoft.com/en-us/library/d2bd4x66%28v=vs.71%29.aspx

The ~ operator flips every bit in an integer type variable. ExitReason is an enum and enums are integer types (for a flag field every element is stored in one bit). ~(ExitReason.Replan | ExitReason.MidRoutePushRequested | ExitReason.ObjectStateChanged | ExitReason.PlayIdle | ExitReason.MaxSkillPointsReached) basically means "all exit reasons except the stated ones. HTH

Consort
2nd Jun 2012, 8:24 PM
Thank you very much:)