Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posting Guidelines

 

Avatar by Lebb

Posted

Got this from Instant C# (vb.net to c# converter):

 

int myInt = 0;

myInt = ~ myInt;

MessageBox.Show(myInt.ToString()); // <-- Reports -1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...