C# string vs String? What are the Differences?


Objective
As a developer are you confused to choose between string and System.String?
In this article I am going to show you all the differences between string and System.String in C# with proper programming example.

What is the Difference between string and String() in C#?

Basically there is no difference between string and String in C#. string is just an alias of System.String and both are compiled in same manner. String stands for System.String and it is a .NET Framework type. string is an alias in the C# language for System.String. Both of them are compiled to System.String in IL (Intermediate Language), so there is no difference.

So, the question is if both string do same job then why need to invent other one to confused programmer. Answer is very simple. String is just a keyword which provides limited functionality and mainly used in creating variable. Whereas, System.String is a class which gives you rich set of functions and properties to manipulate string.

Known Difference between string and System.String

  1. string is a keyword and widely used for declaring variable. Where as System.String is a class and used for accessing string static methods like String.Format(), String.Compare() etc.
  2. You can use string directly in your program and you don’t need to add Using System namespace at the beginning of your program whereas to using System.String you need to import Using System namespace.
  3. As long map to System.Int64, int map to System.Int32 and short map to System.Int16; string map to System.String.

Programming Example

Here, you can see that string is used for declaring variable whereas String is used for accessing static method String.Concat() that join two strings together.

Leave a Reply