[英]Enum bit operations with Mono
I'm trying to port program from .net to Mono on Mac OS X, but I can't compile it while I'm getting compilation error. 我正在尝试将程序从.net移植到Mac OS X上的Mono中,但是在遇到编译错误时无法对其进行编译。 What Should I do to compile it ?
我应该怎么做才能编译它? Why on windows it works fine?
为什么在Windows上可以正常工作?
I'm new to C#, especially on mac os. 我是C#的新手,尤其是在Mac OS上。
namespace my-project
{
using System;
[Flags]
public enum MyEnum : uint
{
F_FLAG_1 = 0x00004,
F_FLAG_2 = 0x00008
}
}
Code line with error: 代码行出现错误:
if ((this.MyEnumField & num) != 0)
Compilation Error message: 编译错误消息:
Error CS0019: Operator `&' cannot be applied to operands of type `MyEnum' and `uint' (CS0019) (my-project)
I'm using Xamarin studio. 我正在使用Xamarin工作室。
I can't read it as anything else than that Mono is in the right, the C# spec has this to say; 我不能读它,除了Mono在右边,C#规范是这样说的。
Enum values and operations
枚举值和运算
Each enum type defines a distinct type;
每个枚举类型定义一个不同的类型。 an explicit enumeration conversion (§6.2.2) is required to convert between an enum type and an integral type , or between two enum types
要在枚举类型和整数类型之间或两个枚举类型之间进行转换,需要显式的枚举转换(第6.2.2节)
...and... ...和...
Enumeration logical operators
枚举逻辑运算符
Every enumeration type E implicitly provides the following predefined logical operators:
每个枚举类型E隐式提供以下预定义的逻辑运算符:
- E operator &(E x, E y);
E运算符&(E x,E y);
- E operator |(E x, E y);
E运算符|(E x,E y);
- E operator ^(E x, E y);
E运算符^(E x,E y);
That is, the logical operators are only defined enum*enum, and to use an integral type in a logical expression with an enum, it should require an explicit cast. 也就是说,逻辑运算符仅被定义为enum * enum,并且要在具有枚举的逻辑表达式中使用整数类型, 应要求进行显式转换。
如果它使用.NET而不是Mono进行编译,则是Mono编译器错误,请在http://bugzilla.xamarin.com/中进行报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.