Difference between string and String in C#

Most of the time we get confused about the string and String class in C#.

Technically, there is no difference between string and String.

string is the Alias for the System.String class. It is just a coding guideline. Microsoft recommended coding style says that, use the string whenever we are creating object of string data type and use String class whenever we want to access the functions of the string class.

Example:

string foo = "world";
string bar = String.Format("Hello {0}!", foo);


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s