-2

I just encountered this line in our code:

inspectActionResult.WorkActionResult &= ~WorkActionResult.Error;

WorkActionResult is a numbered enum, but what does the ~ do???

bas
  • 13,550
  • 20
  • 69
  • 146
  • A [bitwise complement](http://msdn.microsoft.com/en-us/library/d2bd4x66.aspx). – keenthinker Oct 14 '14 at 19:13
  • 2
    @bas Are you aware that C# is comprehensively documented? You might benefit from locating that documentation for future reference. It should be able to help you learn. – David Heffernan Oct 14 '14 at 19:15
  • yeah yeah, I know :). I DID google first, should've came up with the idea of actually writing out "C# tilde"... since "C# ~ enum" didn't give me much. Sorry... :) (at least I get properly downvoted for it) – bas Oct 14 '14 at 19:17
  • I would suggest you to use http://symbolhound.com/ to search for such programming terms. Google usually can't find relevant answers for symbols. Look at the [result for ~ C#](http://symbolhound.com/?q=~+C%23) from symbolhound – Habib Oct 14 '14 at 19:19

1 Answers1

4

That is the logical (bitwise) NOT operator. It will flip all the bits of the operand, and return the result.

In your case, it is un-setting the bit represented by WorkActionResult.Error (due to the &= before it).

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • WOW! that's a fast answer! thx – bas Oct 14 '14 at 19:13
  • 1
    With your reps I can't imagine that you don't know if a duplicate would exists or not. – user2711965 Oct 14 '14 at 19:16
  • @user2711965 Its a duplicate of the second question linked without a doubt (although without the context of unsetting a bit). Not so sure about the first one. Regardless, I was not aware of either of those questions, and would have marked as duplicate if I was. – BradleyDotNET Oct 14 '14 at 19:20