您的位置:首页 > 编程语言 > C#

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

2009-04-28 11:05 417 查看
①string ax=string.Empty;
6ne ~b Kg0注:不要使用: string ax=""; I don't konw why.But it's Microsoft's convention.
0Ys0[ x3tEb Y0判断ax是否为空:
g%xjC%R&W0ax.Length==0 > ax==string.EmptyITPUB个人空间 }'t9JK"eB

Info : "To test for empty strings, check if String.Length is ITPUB个人空间7CG HN}3s/l
equal to zero. Constructs such as "".Equals(someString) ITPUB个人空间:|P/o#SsvH}
and String.Empty.Equals(someString) are less efficient
x{sr9e*I ? r'h&b0 than testing the string length. Replace these with
F)@&?]vA:g%s0r0 checks for someString.Length == 0."
KM#c d5D ];d0
n6F gr4e6y*N]UA$E0②Catch{}要捕获详细异常,不要再乱抛ITPUB个人空间O6N$a0LG-~$VV+R
catch the specific exception than "System.Exception" or rethrow the exception.ITPUB个人空间~XUG/v&iPA'd&{}
Catching generic exception types can hide run-time problems from the library user,ITPUB个人空间3o3[0W"Eph^
and can complicate debugging.

③比较字符串时不要用.ToLower() / .ToUpper()
I2H O G;pqT&M#N0replace by Equals()
?'wgE }.l(W0Don't create a string never used later.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: