title: Determining the first available value in a list of integers
body: <p>I got a simple List of ints.</p>
  
  <pre><code>List&lt;int&gt; myInts = new List&lt;int&gt;();
  
  myInts.Add(0);
  myInts.Add(1);
  myInts.Add(4);
  myInts.Add(6);
  myInts.Add(24);
  </code></pre>
  
  <p>My goal is to get the first unused (available) value from the List.</p>
  
  <p>(the first positive value that's not already present in the collection)</p>
  
  <p>In this case, the answer would be 2.</p>
  
  <p>Here's my current code :</p>
  
  <pre><code>int GetFirstFreeInt()
  {
      for (int i = 0; i &lt; int.MaxValue; ++i)
      {
          if(!myInts.Contains(i))
              return i;
      }
  
      throw new InvalidOperationException("All integers are already used.");
  }
  </code></pre>
  
  <p>Is there a better way? Maybe using LINQ? How would you do this?</p>
  
  <p>Of course here I used ints for simplicity but my question could apply to any type.</p>