因為任何對象添加到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
{
}
catch(Exception exc)
{
}
//推薦
try
{
}
catch(System
{
}
catch(System
{
}
catch(System
{
}
不然在Catch到錯誤後占用的資源不能釋放
try
{
}
catch
{
finally
{
conntion
}
From:http://tw.wingwit.com/Article/program/net/201311/13693.html