1.字符串拼接:
string msg = "Hello, " + thisUser.Name + ".Today is " + DateTime.Now.ToString( ));
更有效率的写法:
string msg = string.Format ( "Hello, {0}. Today is {1}", thisUser.Name, DateTime.Now.ToString( ));
2.大量数据拼接则使用StringBuilder。
3.字符串的比较:
if ( str != "" )与if ( str == "" )
更有效率的写法:
if ( str.Length != 0 )与if ( str.Length ==0 )
有效率且可读性更好的写法:
if ( str != string.Empty )与if( str.Equals(string.Empty)
4.尽量避免box与unbox,因此使用集合时如果频繁更新集合内容,则推荐使用泛型。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-466025/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12639172/viewspace-466025/