可能重复:
What’s the difference between String and string?C#:String类VS串结构
我已经有一段时间使用C#工作,我都没有注意到这两种类型之间的任何性差异。
String myStringAsClass;
string myStringAsStruct;
难道还有比你可以使用的代码或convetion使用来自String类和声明的静态函数从字符串结构澄清以外的任何性差异?
非常感谢!
可能重复:
What’s the difference between String and string?C#:String类VS串结构
我已经有一段时间使用C#工作,我都没有注意到这两种类型之间的任何性差异。
String myStringAsClass;
string myStringAsStruct;
难道还有比你可以使用的代码或convetion使用来自String类和声明的静态函数从字符串结构澄清以外的任何性差异?
非常感谢!
它们是相同的。它们都是参考类型。
System.String == string
System.Object == object
System.Int32 == int
System.Int64 == long
...等等。
C#中的类和结构是有区别的。当然,这是无关在这里,因为
String == string
无一不是class
因此,要总结,还有就是两者之间没有区别,string
是一类。
string
是System.String
的别名,就像int
是System.Int32
的别名一样。
重复的问题和不正确的前提。 'string'不是*结构体 - 它只是'System.String'的别名。 –
这两者之间的唯一区别是'String'需要一个'using System;'指令,因为'string'显式为'global :: System.String',所以不需要任何指令。 –
请参阅http://stackoverflow.com/q/7074/1236044 – jbl