我發現下面的代碼通過網絡搜索,我不明白爲什麼作者使用該類的枚舉。是否有價值限制?它是這樣的,只有'男性'和'女性'的字符串值可以採用哪一種?在這個類中使用枚舉有什麼作用?
public class Person
{
public enum Sex
{
Male,
Female,
}
public string Name { get; set; }
public bool Moustache { get; set; }
public bool Goatee { get; set; }
public bool Beard { get; set; }
public Sex WhichSex { get; set; }
public double Height { get; set; }
public DateTime BirthDate { get; set; }
public bool Favorite { get; set; }
}
也許他們計劃稍後再擴展它。 – Douglas
@Douglas如果他們把它做成旗子,它會更容易 –
'if(WhichSex == Sex.Female &&(Beard || Mustache || Goatee))Favorite = false;' –