【发布时间】:2008-10-02 20:29:50
【问题描述】:
我正在构建一个有趣的小应用程序来确定我是否应该骑自行车上班。
我想测试一下是下雨还是雷暴。
public enum WeatherType : byte
{ Sunny = 0, Cloudy = 1, Thunderstorm = 2, Raining = 4, Snowing = 8, MostlyCloudy = 16 }
我在想我可以这样做:
WeatherType _badWeatherTypes = WeatherType.Thunderstorm | WeatherType.Raining;
if(currentWeather.Type == _badWeatherTypes)
{
return false;//don't bike
}
但这不起作用,因为 _badWeatherTypes 是两种类型的组合。我想将它们分开,因为这应该是一种学习体验,并且将其分开可能在其他情况下很有用(IE,发票未支付原因等......)。
我也不想这样做:(这将取消为多人配置的能力)
if(WeatherType.Thunderstorm)
{
return false; //don't bike
}
etc...
【问题讨论】: