public enum Role { Son = 0, Father = 1, Husband = 2, A = 4, Mother = 8, D = 16, B = 32, C = 64, }
可优化成:
[Flags] public enum Role { Son = 0, Father = 1 << 0,//1 Husband = 1 << 1,//2 A = 1 << 2,//4 Mother = 1 << 3,//8 D = 1 << 4,//16 B = 1 << 5,//32 C = 1 << 6,//64 }
优点是:不用算2的次方。
【Flags】特性表示:该枚举可以进行位运算。
标签:enum,Father,Son,枚举,Flags,Role,优化 From: https://www.cnblogs.com/moon-stars/p/16718602.html