WHAT'S THE DIFFERENCE BETWEEN STRING AND STRING?

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
C# 
C#
 873  View(s)
Ratings:
Rate this:
Hi MindStickians,

In C#, what is the difference between String and string? (note the case)

Example:

string s = "Hello, World";
String S = "Hello, World";

Also, what are the guidelines for the use of each?
Your help is a great appreciated. 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: What's the difference between String and string?

    Hi Tanuj!


    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);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!