ITPub博客

首页 > Linux操作系统 > Linux操作系统 > .NET(C#)代码性能优化

.NET(C#)代码性能优化

原创 Linux操作系统 作者:iDotNetSpace 时间:2009-01-20 16:59:48 0 删除 编辑

①string ax=string.Empty;     
注:不要使用: string ax="";  I don't konw why.But it's Microsoft's convention.
判断ax是否为空:
ax.Length==0   >  ax==string.Empty
    Info         : "To test for empty strings, check if String.Length is
                   equal to zero. Constructs such as "".Equals(someString)
                   and String.Empty.Equals(someString) are less efficient
                   than testing the string length. Replace these with
                   checks for someString.Length == 0."


②Catch{}要捕获详细异常,不要再乱抛
catch the specific exception than "System.Exception" or rethrow the exception.
Catching generic exception types can hide run-time problems from the library user,
and can complicate debugging.

③比较字符串时不要用.ToLower()   /   .ToUpper()
replace by Equals()     
Don't create a string never used later.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-541538/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5321874