这是枚举定义:
[Flags]
enum Animals
{
None = 0,
Dog = 1,
Cat = 2,
Horse = 4,
Zebra = 8,
}
现在,给定以下代码,为什么 HasFlag 方法对 Animals.None 值返回 true?
Animals myAnimals = Animals.Dog | Animals.Horse;
var hasNone = myAnimals.HasFlag(Animals.None); //true! Why?
var hasCat = myAnimals.HasFlag(Animals.Cat); //false
var hasDog = myAnimals.HasFlag(Animals.Dog); //true
var hasHorse = myAnimals.HasFlag(Animals.Horse); //true
var hasZebra = myAnimals.HasFlag(Animals.Zebra); //false