看看这些 c++ 代码:
enum class Flag : int32 {
f_unread = (1 << 0),
f_out = (1 << 1),
f_mentioned = (1 << 4),
MAX_FIELD = (1 << 4),
};
这些代码在c#中隐藏的是什么?
最佳答案
Using Tangible .看起来差别不大。
[Flags]
public enum Flag : int
{
f_unread = (1 << 0),
f_out = (1 << 1),
f_mentioned = (1 << 4),
MAX_FIELD = (1 << 4),
}
在c#中,要使用enum
作为flags操作的位域,需要添加FlagsAttribute
,即添加[FlagsAttribute]
或者[Flags]
在 enum
之前。
关于c# - C++ 中的枚举类 - 替换 - 在 C# 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387986/