I'm trying to convert some VB.net code to C#. I used SharpDevelop to do the heavy lifting; but the code it generated is breaking on some of the enum manipulation and I'm not sure how to fix it manually.
Original VB.net code:
Enum ePlacement
Left = 1
Right = 2
Top = 4
Bottom = 8
TopLeft = Top Or Left
TopRight = Top Or Right
BottomLeft = Bottom Or Left
BottomRight = Bottom Or Right
End Enum
Private mPlacement As ePlacement
''...
mPlacement = (mPlacement And Not ePlacement.Left) Or ePlacement.Right
generated C# code:
public enum ePlacement
{
Left = 1,
Right = 2,
Top = 4,
Bottom = 8,
TopLeft = Top | Left,
TopRight = Top | Right,
BottomLeft = Bottom | Left,
BottomRight = Bottom | Right
}
private ePlacement mPlacement;
//...
//Generates CS0023: Operator '!' cannot be applied to operand of type 'Popup.Popup.ePlacement'
mPlacement = (mPlacement & !ePlacement.Left) | ePlacement.Right;
Resharper suggests adding the [Flags]
attribute to the enum; but doing so doesn't affect the error.
In VB Not
is used for both logical and bitwise NOT.
In C# !
is the boolean NOT and ~
is the bitwise NOT.
So just use:
mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With