Home » Interview Q&A » C# Interview Questions » Difference between String and string in C#

Difference between String and string in C#

Difference Between WCF and WebAPI
Difference between Nullable<> and ?

Difference between String and string

string is an alias in C# for System.String. So technically, there is no difference. It’s like int vs. System.Int32.

Find below code to prove above sentence.

 

As far as guidelines, I think it’s generally recommended to use string any time you’re referring to an object.

e.g.  string place = “world”;

Likewise, I think it’s generally recommended to use String if you need to refer specifically to the class.

e.g.  string technothristy= String.Format(“Hello {0}!”, strWebmaster);

The only difference is without System namespace included, you cannot write “system”, but you can write System.String directly in your code as shown below.

 

About

Hello friends, My self Dhruv Sheth, I have more than 6 years of Industrial experience as a Software Developer. In my career I got chance to work with asp.net, c#,Web API, JavaScript, JQuery, WPF, WCF , Windows Application, PostScript, vb.net, GhostScript etc. So I have decided to share my knowledge with everyone and finally I have come up with TechnoThirsty.




DISCLAIMER:
The content is copyrighted to technothirsty.com and may not be reproduced on other websites without permission from the owner.You may contact us using the information below.