difference-between-String-string-technothirsty

Difference between String and string in C#

Difference between String and string

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

Find below code to prove above sentence.

using System;

class Test
{
    static void Main()
    {
       string s = "Technothirsty";
       String t = "Technothirsty";
       Console.WriteLine(s == t); // True
       Console.ReadKey();
    }
}

 

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 technothristy= String.Format(“Hello {0}!”, strWebmaster);

The only difference is without System namespace included, you cannot write “system”, but you can write System.String directly in your code as shown below.

class Test
{
    static void Main()
    {
       system.String s = "Technothirsty";
       string t = "Technothirsty";// Not allowed

       Console.ReadKey();
    }
}

 

Folks you should also refer below articles for better understanding of differences between: