Logical not, or, etc ...

M

Mr. X.

In VB.NET :
Control cc;
....
cc.Anchor = cc.Anchor and not AnchorStyles.Left and not AnchorStyles.Right;
This sets the Anchor attributes without AnchorStyles.Left,
AnchorStyles.Right;

What is the equivalent code in C# ?

Thanks :)
 
T

Tom Shelton

Mr. X. used his keyboard to write :
In VB.NET :
Control cc;
...
cc.Anchor = cc.Anchor and not AnchorStyles.Left and not AnchorStyles.Right;
This sets the Anchor attributes without AnchorStyles.Left,
AnchorStyles.Right;

What is the equivalent code in C# ?

Thanks :)

cc.Anchor = cc.Anchor & !AncorStyles.Left & !AnchorStyles.Right;

In VB - And and Not are bitwise operators not logical operators. Here
is the basic equivalence:

C# VB
& And
| Or
! Not
&& AndAlso (Logical And)
|| OrElse (Logical Or)
 
J

Jeff Johnson

cc.Anchor = cc.Anchor & !AncorStyles.Left & !AnchorStyles.Right;

In VB - And and Not are bitwise operators not logical operators. Here is
the basic equivalence:

C# VB
& And
| Or
! Not
&& AndAlso (Logical And)
|| OrElse (Logical Or)

I'm pretty sure you don't want ! in this case because that does a
twos-complement inversion and not the pure bit flipping that is desired
here. Use the ~ operator instead:

cc.Anchor = cc.Anchor & ~AnchorStyles.Left & ~AnchorStyles.Right;

Correct me if I'm wrong....
 
T

Tom Shelton

Jeff Johnson laid this down on his screen :
I'm pretty sure you don't want ! in this case because that does a
twos-complement inversion and not the pure bit flipping that is desired here.
Use the ~ operator instead:

cc.Anchor = cc.Anchor & ~AnchorStyles.Left & ~AnchorStyles.Right;

Correct me if I'm wrong....

Your correct... I should have used the ~. I was having a space cadet
moment apparently :)

VB's Not is eqivalent to ~, not !.

Thanks for the correction Jeff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top