gpt4 book ai didi

c# - 确定枚举中缺少哪些标志

转载 作者:行者123 更新时间:2023-11-30 19:05:42 25 4
gpt4 key购买 nike

假设我有下面的枚举:

[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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com