Determining if enum value is in list (C#)

后端 未结 6 2308
抹茶落季
抹茶落季 2021-01-02 12:32

I am building a fun little app to determine if I should bike to work.

I would like to test to see if it is either Raining or Thunderstorm(ing).

publi         


        
6条回答
  •  执笔经年
    2021-01-02 13:11

    You should be using the Flags attribute on your enum. Beyond that, you also need to test to see if a particular flag is set by:

    (currentWeather.Type & WeatherType.Thunderstorm == WeatherType.Thunderstorm)
    

    This will test if currentWeather.Type has the WeatherType.Thunderstorm flag set.

提交回复
热议问题