我项目的开发人员实现了以下枚举
[Flags]
public enum Permissions
{
Overview = 1,
Detail = 3,
Edit = 7,
Delete = 31,
Block = 39, // Requires Edit = 7, and It's own location = 32. Therefore 7 + 32 = 39.
Unblock = 71, // Requires Edit = 7, and It's own location = 64. Therefore 7 + 64 = 71.
All = int.MaxValue
}
现在,如您所见,他已经制作了Details = 3
. 他这样做的原因是Details(应该是2)也包括概述(2+1=3)。
我一直认为做这些事情的方法是在枚举中使用 2 的幂,并在枚举之外进行任何 oring 和 anding。这里发生了什么?