.NET(C#)程式碼效能優化

iDotNetSpace發表於2009-01-20

①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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章