title: How to handle OutOfMemoryException until it does not throw again?
body: <p>I got to know the maximum object size in C# is 2GB. Also there is a memory limit for each particular PC and either it is 32 or 64 bit.</p>
  
  <p>In my application I need an array of integers as big as possible. So what I need is to take care of <code>OutOFMemoryException</code> until the biggest possible array can be made!</p>
  
  <p>I end up with the code below:</p>
  
  <pre><code>private int[] AllIntegers()
  {
      int[] all;
      int divider = 2;
  
      try
      {
          all = new int[int.MaxValue];
      }
      catch (OutOfMemoryException)
      {
          all = new int[int.MaxValue / divider];
      }
      //Probably will fail again. how to efficently loop the catch again
  
      for (int i = 0; i &lt; all.Length; i++)
      {
          all[i] = i;
      }
  
      return all;
  }
  </code></pre>
  
  <p>the code will also fail, what I am looking for is a proper way of looping untill the array can be made!</p>