title: C# Conditional Operator Not a Statement?
body: <p>I have a simple little code fragment that is frustrating me:</p>
  
  <pre><code>HashSet&lt;long&gt; groupUIDs = new HashSet&lt;long&gt;();
  groupUIDs.Add(uid)? unique++ : dupes++;
  </code></pre>
  
  <p>At compile time, it generates the error:</p>
  
  <blockquote>
    <p>Only assignment, call, increment, decrement, and new object expressions can be used as a statement</p>
  </blockquote>
  
  <p><code>HashSet.Add</code> is documented to return a bool, so the ternary (?) operator should work,
  and this looks like a completely legitimate way to track the number of unique and duplicate items I add to a hash-set.</p>
  
  <p>When I reformat it as a if-then-else, it works fine.</p>
  
  <p>Can anyone explain the error, and if there is a way to do this as a simple ternary operator?</p>