string vs System.String in C#

This is one of the frequently asked C# interview question for the beginners. This is very simple but confusing question during interview. In this article I will explain difference between string and System.String in C#.

Actually there is no difference between string and String. string is just an alias created by Microsoft for System.String. string stands for System.String. This alias name is provided so that you don’t need to type every time System.String, you can simply use string in place of it.

Both of them compiled into same code (IL Code – System.String) and within same during execution time.

Let’s understand by an example:

In this example I have taken 2 variables, one is string type and second is System.String type. When I hover mouse on string keyword, it specifies that it refers to System.String.

For using String instead of System.String, you need to include System namespace by using keyword.

Not let’s have a look in Intermediate Language (IL) for this code:


You can see in image, both are same in Intermediate Lanaguage (IL) as well.

string and String are not alone, Microsoft has provided similar aliases for other C# data type as well:

Alias NameC# Data Type
boolSystem.Boolean
byteSystem.Byte
sbyteSystem.SByte
charSystem.Char
decimalSystem.Decimal
doubleSystem.Double
floatSystem.Single
intSystem.Int32
uintSystem.UInt32
longSystem.Int64
ulongSystem.UInt64
objectSystem.Object
shortSystem.Int16
ushortSystem.UInt16
stringSystem.String