Determining if enum value is in list (C#)

后端 未结 6 2357
抹茶落季
抹茶落季 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:12

    I wouldn't limit yourself to the bit world. Enums and bitwise operators are, as you found out, not the same thing. If you want to solve this using bitwise operators, I'd stick to just them, i.e. don't bother with enums. However, I'd something like the following:

            WeatherType[] badWeatherTypes = new WeatherType[]
            {   
                WeatherType.Thunderstorm, 
                WeatherType.Raining
            };
    
            if (Array.IndexOf(badWeatherTypes, currentWeather.Type) >= 0)
            {
                            return false;
            }
    

提交回复
热议问题