在C#编写程序时,你是不是注意到过 String与string的区别,也许你会发现在你编写程序时,他们确实没什么区别,但是,其实不然。
String是CLR的类型名称(也算是keyword),而string是C#中的keyword。在C#的编译时,默认会增加几行代码,看了你就会明白string和String的区别了!
using string = System.String;using sbyte = System.SByte;
using byte = System.Byte;
using short = System.Int16;
using ushort = System.UInt16;
using int = System.Int32;
using uint = System.UInt32; ... ...
对了! using string = System.String; C#编译器,会自动的把string转化为Sysem.string!所以为了减少编译器的工作,建议使用String。
另外string是c#中的类,String是.net Framework的类,(String不会变成蓝色,只会变成浅色) sring是关键字,String不是,也就是说string不能作为类、结构、枚举、字段、变量、方法、属性的名称,而String可以。