Generally, if you want to know which function is more efficient to use different codes, you can use the stopwatch class for testing to improve the Code Performance of program development.
Let's look at a small example. Prerequisite: first reference using system. diagnostics; namespace.
Protected void page_load (Object sender, eventargs E)
{
Stopwatch Sw = new stopwatch ();
Sw. Start (); // start count
Stringbuilder S0 = new stringbuilder ();
For (INT I = 0; I <10000; I ++)
{
S0.append (I );
}
Response. Write (SW. elapsedmilliseconds + "<br/>"); // time used for output in milliseconds
Sw. Reset (); // reset to 0
Sw. Start (); // start count
String S1 = "";
For (INT I = 0; I <10000; I ++)
{
S1 = S1 + I;
}
Response. Write (SW. elapsedmilliseconds + "<br/> ");
Sw. Reset ();
Sw. Start ();
String S2 = "";
For (INT I = 0; I <10000; I ++)
{
S2 + = I;
}
Response. Write (SW. elapsedmilliseconds + "<br/> ");
Sw. Stop ();
}
Execute the code above and get the following results: (it is obvious that the method is efficient)
1
822
681