title: Out of range index in if condition
body: <p>I have a sentence, and I want to check for <em>duplication letters</em> in order to add a <code>'x'</code> as a separator between them, however I debugged and kept getting an exception in here:</p>
  
  <pre><code>for (int i = 0; i &lt; res.Length; i++)
  {
      t += res[i];
  
      if (res[i] == res[i + 1]) //Index out of range exception here
      {
          t += 'x';
      }
  }
  </code></pre>
  
  <p>what goes wrong in here? </p>