1.定义Enum。
[Flags]
public enum FormType
{
Reimburse = 1 ,
Payment = 2 ,
Precharge = 4 ,
PO = 8
}
2.组合枚举值的判断:
public enum FormType
{
Reimburse = 1 ,
Payment = 2 ,
Precharge = 4 ,
PO = 8
}
public
static
void
Print(FormType ft)
{
if((ft&FormType.Reimburse)==FormType.Reimburse)//与判断
{
Console.WriteLine("Reimburse");
}
if((ft&FormType.Payment)==FormType.Payment)
{
Console.WriteLine("Payment");
}
if((ft&FormType.Precharge)==FormType.Precharge)
{
Console.WriteLine("Precharge");
}
if((ft&FormType.PO)==FormType.PO)
{
Console.WriteLine("PO");
}
Console.WriteLine("End");
}
{
if((ft&FormType.Reimburse)==FormType.Reimburse)//与判断
{
Console.WriteLine("Reimburse");
}
if((ft&FormType.Payment)==FormType.Payment)
{
Console.WriteLine("Payment");
}
if((ft&FormType.Precharge)==FormType.Precharge)
{
Console.WriteLine("Precharge");
}
if((ft&FormType.PO)==FormType.PO)
{
Console.WriteLine("PO");
}
Console.WriteLine("End");
}
3.生成组合枚举:
FormType ft
=
FormType.Reimburse
|
FormType.PO;
Print(ft);
运行输出的结果就是:
Print(ft);
Reimburse
PO