我有一个如果条件为一个枚举。我的枚举是:如何使用标志如果条件
public enum EmploymentType
{
Type1 = 1,
Type2 = 2,
Type3 = 3
}
并在此条件
EmploymentType type = EmploymentType.Type1 ;
if (type.HasFlag(EmploymentType.Type1 | EmploymentType.Type2)) //if (type == (EmploymentType.Type1 | EmploymentType.Type2))
{
return true;
}
else
{
return false;
}
预期的真实结果此条件,但结果是假的。为什么?
为什么不呢,'如果(类型== EmploymentType.Type1 ||类型== EmploymentType.Type2)' – 2012-01-01 12:36:11
请阅读此:[枚举标志属性](http://stackoverflow.com/questions/8447/enum-flags-attribute)。 – 2012-01-01 12:36:31