why foreach is faster than for loop while reading richtextbox lines

前端 未结 5 2001
忘掉有多难
忘掉有多难 2020-12-21 00:49

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(in         


        
5条回答
  •  离开以前
    2020-12-21 01:19

    Could it be that each line is being copied to a new string variable (str) on each loop? I'm guissing here, but you could probably verify the theory with this code

    String s = String.Empty;
    for (int i = 0; i < richTextBox.Lines.Length; i++)
    {
        string str = richTextBox.Lines[i];
        s = str;
    }
    

提交回复
热议问题