Tôi đang cố chuyển đổi một số mã VB.net thành C#. Tôi đã sử dụng SharpDevelop để thực hiện việc nâng hạng nặng; nhưng mã nó tạo ra là phá vỡ trên một số thao tác enum và tôi không chắc chắn làm thế nào để sửa chữa nó bằng tay.C# tương đương với "Not MyEnum.SomeValue"
VB.net mã gốc:
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
tạo mã C#:
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 gợi ý thêm các thuộc tính [Flags]
để enum; nhưng làm như vậy không ảnh hưởng đến lỗi.
Ngay cả với các nhà điều hành đúng, bạn nên vẫn có [Flags] thuộc tính. – plinth
lỗi được báo cáo tại Sharpdevelop: http://community.sharpdevelop.net/forums/p/16388/44685.aspx –