title: C#: Most elegant way to test if int x is element of a given set?
body: <p>Problem: Test if x ∉ { 2, 3, 61, 71 }</p>
  
  <p>I often wondered if there is not a better way than:</p>
  
  <pre><code>if (x != 2 &amp;&amp; x != 3 &amp;&amp; x != 61 &amp;&amp; x != 71)
  {
    // do things
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if (!new List&lt;int&gt;{ 2, 3, 61, 71 }.Contains(x))
  {
    // do things
  }
  </code></pre>
  
  <p>The latter one seems quite elegant, but actually it is kind of irritating if you read it, especially because of the inversion. It's kind of an ugly thing because in English we say <em>"x is not element of ..."</em>, which is hard to express in C# without irritating overhead. Maybe one coud say <code>if (Object(x).IsElementOf(new[] { ... }))</code> or so?</p>
  
  <p>Hmm.. any suggestions? Are there any .Net standard methods to test things like that?</p>