title: What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
body: <p>I have some code and when it executes, it throws a <code>IndexOutOfRangeException</code>, saying, </p>
  
  <blockquote>
    <p>Index was outside the bounds of the array.</p>
  </blockquote>
  
  <p>What does this mean, and what can I do about it?</p>
  
  <p>Depending on classes used it can also be <code>ArgumentOutOfRangeException</code></p>
  
  <blockquote>
    <p>An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code Additional information: Index was out of range. Must be non-negative and less than the size of the collection.</p>
  </blockquote>