A string and StringBuilder
A small number of string operations should not be used StringBuilder.
Because a string is not an object, each operation generates a new string object for the superposition of strings. So for a lot of string operations, we use Stringbuilde. But it seems that a lot of people know this, so as long as the strings are added, no matter 3721 is StringBuilder. In fact, this is a misunderstanding, here to pay attention to the word "mass", a small number of string operations with StringBuilder rather than outweigh the gains.
For example, the following two ways:
String sql = "INSERT into table (,,,)";
SQL + = "VALUES (')";
StringBuilder sb = new StringBuilder ();
Sb. Append ("INSERT into table (,,,)");
Sb. Append ("VALUES (')");
string s = sb. ToString ();
It is advisable to adopt the first formulation. Because there are only two strings added, not much. If you use StringBuilder, you end up with a string, which results in a poor performance.
Second caution with abnormal
Because the program throws an exception, an exception object is created, and then the application catches the exception in the catch block, resulting in a very high performance impact.
Like what:
int OrderID;
Try
{
OrderID = Convert.ToInt32 (This.txtOrderID.Text);
}
catch (Exception e)
{
OrderID =.
}
Such code is not appropriate, resulting in a very high performance overhead. You should write the JS code on the client first to verify that the Txtorderid meets the requirements.
Three about session, Request
Session:
Many people like to use the session to save the values of persistent objects. However, when your program is deployed on multiple servers to do load balancing, you may not get the value of the variables saved by the session. In addition, since the session is a server-side built-in object, every session object is opened, and resources are occupied on the server.
Request:
When you pass values between pages, you see a lot of people writing code like this:
String CustomerName = this. request["Txtcustomername"]. ToString ();
In fact, the back of ToString () superfluous. This. Request["..."] is a string type, no need to go to ToString () again.
Write so much today, and have other questions to add.