why foreach is faster than for loop while reading richtextbox lines
问题 There are two ways to read data from RichTextBox line by line 1 ) use a for loop to loop through lines of a richtextBox String s=String.Empty; for(int i=0;i<richtextbox.lines.length;i++) { s=richTextBox.Lines[i] } 2 ) use a foreach loop to enumerate richTextBox.Lines collection String s=String.Empty; foreach(string str in txtText.Lines) { s=str; } There is a huge difference in performance when we use foreach loop to enumerate array collection for richtextbox. I tried with 15000 lines.for loop