Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.22/5 (7 votes)
See more:
In C#, what is the difference between String and string? (note the case)

Example:

C#
string s = "Hello, World";

String S = "Hello, World";
Posted
Comments
adriancs 3-Jun-14 6:00am    
Yes he is.

string is an alias for System.String. So technically, there is no difference. It's like int vs. System.Int32.

As far as guidelines, I think it's generally recommended to use string any time you're referring to an object.

e.g. string place = "world";

Likewise, I think it's generally recommended to use String if you need to refer specifically to the class.

e.g. string greet = String.Format("Hello {0}!", place);

This is the style that Microsoft tends to use in their examples.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Jun-14 11:48am    
What would be your rationale for preferring "String" over "string", ever? Why not "System.String" then? What does it mean, "specifically do the class"? When do you think it is "specifically" referred and when not?

Please, without referring to Microsoft, which often shows ugly style. Referring to authorities is anti-scientific, should not be taken seriously. Any rational arguments?
—SA
String:
1.String is an class(System.String)
2.String is an Reference type(class)

string:
1.string is an alias name of String class that is created by microsoft
2.string is an value type(data type)
3.string is a C# keyword
4.string is a compiler shortcut for System.String class

As per above points when we use string keyword, it reaches the System.String class and then process accordingly, So we can say that both String and string are same.
 
Share this answer
 
Comments
Nirav Prabtani 2-Jun-14 3:21am    
When you copy exact content from any other website than you should mention reference url

http://www.dotnetfunda.com/interviews/show/3832/difference-between-string-and-string-in-csharp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900