All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
如何自动发布MS,SQL,SERVER数据库_[SQL,Server教程]
学习PHP:详解mysql4.0以后的编码配置_php资料_编程技术
C#中ToolTip控件应用实例
.NET2.0DataList分页_[Asp.Net教程]
ASP.NET Remoting体系结构(七)
轻松检测浏览器是否接受Cookies信息_.net资料_编程技术
.net2.0中使用SqlBulkCopy进行大批量数据迁移_[Asp.Net教程]
Asp.NET写文件_.net资料_编程技术
基于PHP的AJAX技术实现文件异步上传_[PHP教程]
利用.net反射动态调用指定程序集的中的方法_[Asp.Net教程]
Reading number is top 10 pictures
张家界的玻璃桥
可爱的小动物
Compared GDP and per capita income in China for 40 years
Go to the national museum2
看如何给单纯的少女洗脑
a pure sister
俄罗斯台球天后惊艳魅惑2
南昌铁路局宜春车务段攸县车站铁路职工福利房被开发商侵占
Sexy women in 2013--1
Fierce! China's special forces training the devil1
Download software ranking
美女写真1
Boxer's Top ten classic battle7
电车之狼R
Sora aoi - one of more PK
软件工程思想
Sora aoi 120 minutes
都市狐狸姑娘传
Macromedia Dreamweaver 8
Tram sex maniac 2 (H) rar bag5
Sora aoi, the maid, students' uniforms
aaa published in(发表于) 2013/12/13 9:43:23 Edit(编辑)
如何最大限度提高.NET的性能_.net资料_编程技术

如何最大限度提高.NET的性能_.net资料_编程技术

如何最大限度提高.NET的性能_.net资料_编程技术-你的首页-uuhomepage.com

优化 .NET的性能


1)避免使用ArrayList。
因为任何对象添加到ArrayList都要封箱为System.Object类型,从ArrayList取出数据时,要拆箱回实际的类型。建议使用自定义的集合类型代替ArrayList。.net 2.0提供了一个新的类型,叫泛型,这是一个强类型,使用泛型集合就可以避免了封箱和拆箱的发生,提高了性能。


2)使用HashTale代替其他字典集合类型(如StringDictionary,NameValueCollection,HybridCollection),存放少量数据的时候可以使用HashTable.


3)为字符串容器声明常量,不要直接把字符封装在双引号" "里面。
//避免
//
MyObject obj = new MyObject();
obj.Status = "ACTIVE";


//推荐
const string C_STATUS = "ACTIVE";
MyObject obj = new MyObject();
obj.Status = C_STATUS;


4) 不要用UpperCase,Lowercase转换字符串进行比较,用String.Compare代替,它可以忽略大小写进行比较.

例:

const string C_VALUE = "COMPARE";
if (String.Compare(sVariable, C_VALUE, true) == 0)
{
Console.Write("SAME");
}



5) 用StringBuilder代替使用字符串连接符 “+”,.


//避免
String sXML = "";
sXML += "";
sXML += "Data";
sXML += "
";
sXML += "
";


//推荐
StringBuilder sbXML = new StringBuilder();
sbXML.Append("");
sbXML.Append("");
sbXML.Append("Data");
sbXML.Append("
");
sbXML.Append("
");


6) If you are only reading from the XML object, avoid using XMLDocumentt, instead use XPathDocument, which is readonly and so improves performance.
如果只是从XML对象读取数据,用只读的XPathDocument代替XMLDocument,可以提高性能
//避免
XmlDocument xmld = new XmlDocument();
xmld.LoadXml(sXML);
txtName.Text = xmld.SelectSingleNode("/packet/child").InnerText;


.


//推荐
XPathDocument xmldContext = new XPathDocument(new StringReader(oContext.Value));
XPathNavigator xnav = xmldContext.CreateNavigator();
XPathNodeIterator xpNodeIter = xnav.Select("packet/child");
iCount = xpNodeIter.Count;
xpNodeIter = xnav.SelectDescendants(XPathNodeType.Element, false);
while(xpNodeIter.MoveNext())
{
sCurrValues += xpNodeIter.Current.Value+"~";
}



7) 避免在循环体里声明变量,应该在循环体外声明变量,在循环体里初始化。


//避免
for(int i=0; i<10; i++)
{
SomeClass objSC = new SomeClass();
.
.
.


}


//推荐
SomeClass objSC = null;
for(int i=0; i<10; i++)
{
objSC = new SomeClass();

.
.
.
}


8) 捕获指定的异常,不要使用通用的System.Exception.


//避免
try
{

}
catch(Exception exc)
{

}

//推荐
try
{

}
catch(System.NullReferenceException exc)
{

}
catch(System.ArgumentOutOfRangeException exc)
{

}
catch(System.InvalidCastException exc)
{

}


9) 使用Try...catch...finally时, 要在finally里释放占用的资源如连接,文件流等
不然在Catch到错误后占用的资源不能释放。

try
{
...
}
catch
{...}
finally
{
conntion.close()
}
10) 避免使用递归调用和嵌套循环,使用他们会严重影响性能,在不得不用的时候才使用。


11) 使用适当的Caching策略来提高性能
好了 今天就写到这里, 以后有空再写。






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.