实现效果如FlagsAttribute 那样, 可以有多重属性, 赋值方法如 "FlagsAttribute.Hidden | FlagsAttribute.ReadOnly "
首先定一个enum类型
例:
1
enum
Test
2
{3 T1 = 1,4 T2 = 2,5 T3 = 4,6 T4 = 8,7 T5 = 168}
每一个元素的值一定要是2 的幂 如 2, 4 ,8, 16 等
应用:
[STAThread]
static
void
Main(
string
[] args)
{ Test t = Test.T1 | Test.T3; if ( (t & Test.T1) > 0 ) { Console.WriteLine("is T1"); } else { Console.WriteLine("isn't T1"); } if ((t & Test.T2) > 0 ) { Console.WriteLine("is T2"); } else { Console.WriteLine("isn't T2"); } Console.ReadLine(); }
输出结果 :
is T1
isn't T2
转载于:https://www.cnblogs.com/skyfei/archive/2006/09/18/507754.html