.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.
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.
相关文章推荐
- .NET(C#)代码性能优化
- .NET(C#)代码性能优化_AX
- C# 代码优化 性能优化【转】
- C#、.Net代码精简优化(空操作符(??)、as、string.IsNullOrEmpty() 、 string.IsNullOrWhiteSpace()、string.Equals()、System.IO.Path 的用法)
- 35 个 Java 代码性能优化总结
- JavaScript代码性能优化总结
- [转] Python 代码性能优化技巧
- Java性能优化之数据结构实例代码
- Android代码性能优化技巧 (一)
- C#程序性能优化
- 35 个 Java 代码性能优化总结
- .net中C#代码与javaScript函数的相互调用问题
- java 性能优化:35 个小细节,让你提升 java 代码的运行效率
- C# 性能优化方面的总结(转)
- Android 性能优化:使用 Lint 优化代码、去除多余资源,减少APP的size
- 35 个 Java 代码性能优化总结
- android的代码性能优化
- 系统性能调优(5)----Java循环与字符串代码优化
- 35 个 Java 代码性能优化总结
- python和c性能比较,以及用dll优化python代码