Difference between String and string in c#

c# difference in string and String

There is no such difference between string and String (Syetem.String). The "string" keyword is an alias for System.String in the .NET Framework. So the String and string are equal and you can use whichever naming convention you prefer.

C# Objects

c# String object

Everything in C# language is an Object, there are no primitive types in the classic sense. That means string is not a truly primitive types, it is an object instance of a Class. Syetem.String and string are compiled to System.String in Intermediate Language (IL), so there is no difference in the performance, and it's purely a personal choice.

More about.....C# String


c# String

In C#, string is a keyword in Base Class Library (BCL) directly maps to System.String (a Framework Class Library (FCL) type). Base Class Library (BCL) is the standard for the C# runtime library and one of the Common Language Infrastructure (CLI) standard libraries. The Framework Class Library (FCL) containing reusable classes and is a superset of the BCL classes and refers to the entire class library that ships with .NET Framework.

Which one should I use?

According to C# language specification, as a matter of style the keyword 'string' is preferred over the full system type name System.String, so there is no difference and either can be used.

More about.....Is String in .Net immutable ?

Data Type Alias in .Net


In .Net Data Type aliasing allows us to use an alias of a datatype instead of real data type name. Following are the list of some other aliases using in C# Language.

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

NEXT.....Dictionary in C#