Mike_R Posted December 14, 2004 Posted December 14, 2004 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#:Dim myInt as Integer = 0 myInt = Not myInt MessageBox.Show(myInt.ToSting) ' <-- Reports -1 In C# I tried this: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 Quote Posting Guidelines Avatar by Lebb
Jaco Posted December 14, 2004 Posted December 14, 2004 Got this from Instant C# (vb.net to c# converter): int myInt = 0; myInt = ~ myInt; MessageBox.Show(myInt.ToString()); // <-- Reports -1 Quote
Mike_R Posted December 15, 2004 Author Posted December 15, 2004 Ah, right! I really should have known that... thank you, Jaco. :) Quote Posting Guidelines Avatar by Lebb
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.