What is the difference between String and string in C#?

后端 未结 30 3834
走了就别回头了
走了就别回头了 2020-11-21 04:35

Example (note the case):

string s = \"Hello world!\";
String s = \"Hello world!\";

What are

30条回答
  •  礼貌的吻别
    2020-11-21 05:29

    string is a keyword, and you can't use string as an identifier.

    String is not a keyword, and you can use it as an identifier:

    Example

    string String = "I am a string";
    

    The keyword string is an alias for System.String aside from the keyword issue, the two are exactly equivalent.

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

提交回复
热议问题