正在研究如何通过使用 flags 属性和 bitwize 运算符装饰枚举来将它们用作位标志(见下文)。
.NET 框架中是否有使用此模式的地方?我喜欢这个,但想看看更多现实生活中的例子
[Flags]
enum Days2 : int
{
None = 0x0,
Sunday = 0x1,
Monday = 0x2,
Tuesday = 0x4,
Wednesday = 0x8,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40
}
Days2 meetingDays = Days2.Tuesday | Days2.Thursday;
// Set an additional flag using bitwise OR.
meetingDays = meetingDays | Days2.Friday;
Console.WriteLine("Meeting days are {0}", meetingDays);