C#的Enum设计的相关指导在网上有相关文章论述:
英文:Design Guidelines Update: Enum Design
中文:C# Idioms: Enum还是Enum Class(枚举类)
技巧1:如何去除一个枚举项:
例如定义了权限Enum Permission:
[Flags]
public enum Permission{
Select = 1,
Edit = 2,
Delete = 4,
View = 8,
All = Select | Edit | Delete | View
}
可以采用这个函数进行计算:
public static Permission ClearFlag(Permission value, Permission flag)
{
value = value & (Permission.All^ flag);
return value;
}