C# string vs String

来源:互联网 发布:免费光盘刻录软件 编辑:程序博客网 时间:2024/05/21 06:47

string 是 System.String的别名. 从技术上讲,它们没有区别,就像int vs System.Int32.


typeof(string) == typeof(System.String). 


从编码规范上看,当声明一个对象实例时通常推荐使用 string:
例如:string place = "world";
当需要特别指涉到类时,通常推荐使用String.
例如:
string greet = String.Format("Hello {0}!", place);
 
Microsoft所给的例子中用的是这种风格。
但是也有不同看法的。如果用string,就所有地方都用string,代码统一。
StyleCop强制使用C#语言特定的别名string.

0 0
原创粉丝点击