惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
小众软件
小众软件
美团技术团队
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
D
Docker
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
B
Blog
雷峰网
雷峰网
The Cloudflare Blog

博客园 - Koven

如何拓展你的人脉关系 所谓职业(转载) 期待已久的一本电子书出来了:Applying Domain-Driven Design and Patterns: With Examples in C# and .NET 搜索引擎相关站点收集(转载) 中文搜索引擎系统架构(转载) 中文搜索引擎网络蜘蛛(转载) 中文搜索引擎中的排序技术(转载) 中文分词介绍(转载) 转载一篇不错的关于.NET中内存使用的文章 Data Type Performance Tuning Tips for Microsoft SQL Server(转载) 怎么在ASP.NET 2.0中使用Membership (转载) HttpModule 示例(转载) ASP.NET服务器控件与组件基础概念——HttpHandler (转载) ASP.NET服务器控件与组件基础概念——HttpModule(转载) Tips to improve the performance of ASP.Net Application HTTP运行期与页面执行模型(转载) XML格式的网站配置文件常见读写方案比较(转载) ASP.NET应用中十大常见的潜在问题(转载) 微软研发75条心得(转载)
Best practices for .Net Performance - I
Koven · 2006-08-08 · via 博客园 - Koven

Best practices for .Net Performance

1) Avoid the use of ArrayList. Because any objects added into the Arraylist are added as System.Object and when retrieving values back from the arraylist, these objects are to be unboxed to return the actual valuetype. So it is recommended to use the custom typed collections instead of ArrayList.

2) Reconsider the use of Hashtable instead try other dictionary such as StringDictionary, NameValueCollection, HybridCollection. Hashtable can be used if less number of values are stored.

3) Always declare constants for the string literals you use instead of enclosing them in "".

 //AVOID
 //
 MyObject obj = new MyObject();
 obj.Status = "ACTIVE";

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

4) Donot compare strings by converting them to uppercase or lowercase, use String.Compare instead, which can ignore the case and compare.
   Ex:
 const string C_VALUE = "COMPARE";
 if(String.Compare(sVariable, C_VALUE, true)==0)
 {
  Console.Write("SAME");
 }

5) Avoid String concatenation using + operator, instead use StringBuilder for concatenation.

6) If you are only reading from the XML object, avoid using XMLDocumentt, instead use XPathDocument, which is readonly and so improves performance.

7) Avoid declaring objects/variables inside loops, instead declare the variable once outside the loop and initialize them inside.

8) Always catch the Specific exceptions instead of generic System.Exception.