title: why foreach is faster than for loop while reading richtextbox lines
body: <p>There are two ways to read data from RichTextBox line by line</p>
  
  <p>1 ) use a for loop to loop through lines of a richtextBox</p>
  
  <pre><code>String s=String.Empty;
  for(int i=0;i&lt;richtextbox.lines.length;i++)
   {
       s=richTextBox.Lines[i]
   }
  </code></pre>
  
  <p>2 ) use a foreach loop to enumerate richTextBox.Lines collection</p>
  
  <pre><code>   String s=String.Empty;
     foreach(string str in txtText.Lines)
      {
         s=str;
      }
  </code></pre>
  
  <p>There is a huge difference in performance when we use foreach loop to enumerate array collection for richtextbox.</p>
  
  <p>I tried with 15000 lines.for loop took 8 minutes to just loop down to 15000 lines.while foreach took fraction of a second to enumerate it. </p>
  
  <p>Why is this behaviour there?</p>