Bitwise 'Not' Operator in C#?

Mike_R

Junior Contributor
Joined
Oct 20, 2003
Messages
316
Location
NYC
Sorry for such a ludicrously n00b question... But what is the bitwise 'Not' operator in C#? In short, I'm trying to replicate this VB.Net code in C#:
Visual Basic:
Dim myInt as Integer = 0
myInt = Not myInt
MessageBox.Show(myInt.ToSting) ' <-- Reports -1
In C# I tried this:
Code:
int myInt = 0
myInt = !myInt  // <-- Compile Time Error
MessageBox.Show(myInt.ToSting)
But the above complains that the '!' operator does not apply for Integers. I guess it's for booleans only? So what is the easiest way to do this in C#? I can't imagine that I have to resort to a Collections.BitArray, do I?

Much thanks in advance...
Mike
 
Got this from Instant C# (vb.net to c# converter):

int myInt = 0;
myInt = ~ myInt;
MessageBox.Show(myInt.ToString()); // <-- Reports -1
 
Back
Top