Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your current code will say whether it's <em>exactly</em> "raining and thundery". To find out whether it's "raining and thundery and possibly something else" you need:</p> <pre><code>if ((currentWeather.Type &amp; _badWeatherTypes) == _badWeatherTypes) </code></pre> <p>To find out whether it's "raining <em>or</em> thundery, and possibly something else" you need:</p> <pre><code>if ((currentWeather.Type &amp; _badWeatherTypes) != 0) </code></pre> <p>EDIT (for completeness):</p> <p>It would be good to use the <code>FlagsAttribute</code>, i.e. decorate the type with <code>[Flags]</code>. This is not necessary for the sake of this bitwise logic, but affects how <code>ToString()</code> behaves. The C# compiler ignores this attribute (at least at the moment; the C# 3.0 spec doesn't mention it) but it's generally a good idea for enums which are effectively flags, and it documents the intended use of the type. At the same time, the convention is that when you use flags, you pluralise the enum name - so you'd change it to <code>WeatherTypes</code> (because any actual value is effectively 0 or more weather types).</p> <p>It would also be worth thinking about what "Sunny" really means. It's currently got a value of 0, which means it's the absence of everything else; you couldn't have it sunny and raining at the same time (which is physically possible, of course). Please don't write code to prohibit rainbows! ;) On the other hand, if in your real use case you genuinely want a value which means "the absence of all other values" then you're fine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload