Introduction
Many times, developers try to understand what is actually the difference in String vs string in C#. For that, we need to know that C# is a language used with the CLR.
- String is a type in the CLR
- string is a type in C#
- we can't use String without using System; namespace
- string is also known as an alias in C# for String.
So from a technical point of view, there is no difference.
For the best practice in C#, the recommendation is to use string when you refer to the object.
Like: string name = "Smith";
And when we need to refer the class then the recommendation is to use String
Like: string welcomeName = String.Format("Welcome {0}!", name);
If we talk about from compilation point of view so they compile the same code and take some time for execution
Key Difference
string is provided by Microsoft so it is a reserved word, while String is just a class name.
This is the reason that string cannot be used as a variable name.
- //this is compile code
- StringBuilder String = new StringBuilder(); // valid
- // this is incompile code
- StringBuilder string = new StringBuilder(); // invalid

Note
Only string and object are reference types, the other aliases are all value types.
The complete list is:

Join the conversation! Your thoughts help the community grow.