我发现下面的代码通过网络搜索,我不明白为什么作者使用该类的枚举。是否有价值限制?它是这样的,只有'男性'和'女性'的字符串值可以采用哪一种?在这个类中使用枚举有什么作用?
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;' –