string 和 System.String的比较(转阿良兄和niwalker兄文章)

阿良兄文章:

string是c#中的类,
String是.net Framework的类(在c# IDE中不会显示蓝色)
c# string映射为.net Framework的String
如果用string,编译器会把它编译成String,所以如果直接用String就可以让编译器少做一点点工作
如果使用c#,建议使用string,比较符合规范 string始终代表 System.String(1.x) 或 ::System.String(2.0) ,String只有在前面有using System;的时候并且当前命名空间中没有名为String的类型(class、struct、delegate、enum)的时候才代表System.String string是关键字,String不是,也就是说string不能作为类、结构、枚举、字段、变量、方法、属性的名称,而String可以


niwalker兄文章

string属于C#的类型
String属于.NET 的类型 在.NET 所有的类型都是对象。
下面是.NET C# VB.NET IL的类型对应表:
NET              C#       VB.NET        IL     值或引用
System.Boolean  bool      Boolean     bool        Value
System.Byte     byte      Byte    unsigned int8   Value
System.Char     char      Char        char        Value
System.DateTime  -         Date        -             Value
System.Decimal decimal    Decimal     -             Value
System.Double   double    Double     float64      Value
System.Int16    short     Short      int16        Value
System.Int32    int       Integer    int32        Value
System.Int64    long       Long      int64        Value
System.Object   object    Object     object     Reference
System.SByte     sbyte     -           int8         Value
System.Single   float     Single      float32      Value
System.String    string    String     string     Reference
System.UInt16    ushort    -      unsigned int16    Value
System.UInt32    uint      -      unsigned int32     Value
System.UInt64    ulong    -       unsigned int64     Value

从上表可以看到,不仅仅string和String,还有许多类似的类型。有的没有对应的类型,这时使用的就是.NET的,比如说在C#中没有date类型,所以在C#中我们使用.NET 的Date. 这也是.NET的跨语言特性之一。
原文地址:https://www.cnblogs.com/qingwa008/p/1160983.html