• C#中的String与string


      在C#中,string 是 System.String 的别名,所以基本上在使用时是没有差别的。

      习惯上,我们把字符串当作对象时(有值的对象实体),我们用string。

      而我们把它当类时(需要字符串类中定义的方法),我们用String,比如:string greet = String.Format("Hello {0}!", place)。

      其实乱用也可以,只是这样概念上清楚一点。

      另外string是C#保留字,不可用作变量名,String就不是了。 String 必须先引用 System命名空间。

        也可以这样理解:string是C#中字符串类型String的反射,一种简化的书写方式,就像int对应于Int32一样,二者在C#中可通用。

      再则String是一个类,string是一种数据类型。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.Stringstring是关键字,String不是,也就是说string不能作为类、结构、枚举、字段、变量、方法、属性的名称,而String可以。

  • 相关阅读:
    Finite Difference Method with Mathematica
    评论
    The Woman in Red Is Seen as a Threat by Other Wom
    Why Does Everyone Else Appear to Be Succeeding?
    The Sorrows of Young Werther
    【洛谷P5607】无力回天 NOI2017
    【YbtOJ#532】往事之树
    【YbtOJ#582】大收藏家
    【牛客Wannafly挑战赛23 F】计数
    【YbtOJ#573】后缀表达
  • 原文地址:https://www.cnblogs.com/Jolinson/p/3497500.html
Copyright © 2020-2023  润新知