.NET(C#)代码性能优化
2009-01-20 16:31
357 查看
①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.
【待续】
注:不要使用: 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.
【待续】
相关文章推荐
- .NET(C#)代码性能优化_AX
- .NET(C#)代码性能优化
- 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
- android的代码性能优化
- 35 个 Java 代码性能优化总结
- 系统性能调优(5)----Java循环与字符串代码优化
- 35 个 Java 代码性能优化总结
- python和c性能比较,以及用dll优化python代码