title: How to handle Index out of range in a better way
body: <p>My code was giving me Index out of Range exception for a certain input. Below is the problematic code:</p>
  
  <pre><code>string[] snippetElements = magic_string.Split('^');
  
  string a = snippetElements[10] == null ? "" : "hello";
  string b = snippetElements[11] == null ? "" : "world";
  </code></pre>
  
  <p>For that particular  input, array snippetElements had only one element in it, hence while trying to index 10th and 11th element, I got the exception.</p>
  
  <p>For now, I have introduced the following check:</p>
  
  <pre><code>if (snippetElements.Length &gt;= 11)
  {
      string a = snippetElements[10] == null ? "" : "hello"; 
      string b = snippetElements[11] == null ? "" : "world";
  }
  </code></pre>
  
  <p>Can someone suggest a better way to write this check. Somehow the number 11 is not looking good in the code.</p>