假设我有下面的枚举:
[Flags]
public enum NotifyType
{
None = 0,
Window = 1 << 0,
Sound = 1 << 1,
Flash = 1 << 2,
MobileSound = 1 << 3,
MobilePush = 1 << 4
}
考虑两个枚举:
var myenums = Window | Sound | Flash;
//var possibleUpdate = Window | MobilePush;
void UpdateMyEnums(NotifyType possibleUpdate)
{
//Does myenums contain all the flags in 'possibleUpdate'? If not add
//the missing flags to myenums
}
与 possibleUpdate
相比,如何确定 myenums
变量不包含 NotifyType.MobilePush
值?我是否必须针对 myenums
测试 possibleUpdate
中的每个标志?
我在 .NET 4.0 上使用 C#
最佳答案
if (myenums & possibleUpdate != possibleUpdate)
//not a possible update
要获取 myenums
中不需要的标志:
NotifyType missing = (~(myenums ^ wanted) ^ wanted) & (myenums | wanted);
关于c# - 确定枚举中缺少哪些标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18323031/