優化
因為任何對象添加到ArrayList都要封箱為System
//避免
//
MyObject obj = new MyObject();
obj
//推薦
const string C_STATUS =
MyObject obj = new MyObject();
obj
例
const string C_VALUE =
if (String
{
Console
}
//避免
String sXML =
sXML +=
sXML +=
sXML +=
sXML +=
//推薦
StringBuilder sbXML = new StringBuilder();
sbXML
sbXML
sbXML
sbXML
sbXML
如果只是從XML對象讀取數據
//避免
XmlDocument xmld = new XmlDocument();
xmld
txtName
//推薦
XPathDocument xmldContext = new XPathDocument(new StringReader(oContext
XPathNavigator xnav = xmldContext
XPathNodeIterator xpNodeIter = xnav
iCount = xpNodeIter
xpNodeIter = xnav
while(xpNodeIter
{
sCurrValues += xpNodeIter
}
//避免
for(int i=
{
SomeClass objSC = new SomeClass();
}
//推薦
SomeClass objSC = null;
for(int i=
{
objSC = new SomeClass();
}
//避免
try
{
<some logic>
}
catch(Exception exc)
{
<Error handling>
}
//推薦
try
{
<some logic>
}
catch(System
{
<Error handling>
}
catch(System
{
<Error handling>
}
catch(System
{
<Error handling>
}
不然在Catch到錯誤後占用的資源不能釋放
try
{
}
catch
{
finally
{
conntion
}
好了 今天就寫到這裡
From:http://tw.wingwit.com/Article/program/ASP/201311/21744.html