Checking valid combination of items in list
<p>I have a list of items that I need to validate. The list can contain any number of items of the type A, B and C, but before the list can be saved, it must confirm to the following rules:</p>

<ol>
<li>If you have A, you need either B or C  </li>
<li>If you have B, you need A</li>
</ol>

<p>I have ended up with the following code (saudo code):</p>

<pre><code>bool IsListValid()
{
  var a = list.ContainsAny(A);
  var b = list.ContainsAny(B);
  var c = list.ContainsAny(C);

  if (!a &amp;&amp; !b)
    return true;

  if (a &amp;&amp; (b || c)
    return true;

  return false;
}
</code></pre>

<p>I don't like this code.<br>
1. The use of Any three times in a row will potentially iterate the list three times<br>
2. The if's doesn't look good to me. </p>

<p>Of cause it would be better with different variable names and by extracting the test into methods with good names, but I think there are better ways of solving this entirely. I'm just not sure how...</p>

<p>Any tips?</p>
