Difference between string and System.String

Posted on Posted in General

The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework. C# defines a number of aliases for CLR types which can be used interchangably or even mixed together.

eg. string x = new System.String(' ', 5);

Although string is a reference type, the equality operators (== and !=) are defined to compare the values of string objects, not references. This makes testing for string equality more intuitive.

Some more defined C# aliases are:

string System.String
sbyte System.SByte
byte System.Byte
short System.Int16
ushort System.UInt16
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
char System.Char
float System.Single
double System.Double
bool System.Boolean
decimal System.Decimal

Leave a Reply

Your email address will not be published. Required fields are marked *