In this article, we discuss "What is the difference between string and String in C#?".
In C#, string
is an alias for the String class in .NET framework. Anything you can do with System.String
, you can also do with string
. Both are derived from System.String
. So, technically both of these are the same but with a slight difference.
String
, you need a namespace "System" while for using "string
", there is no need of namespace "System
".string world = "world";
string str = String.Format("Hello {0}", world);
//Output Will be "Hello World"
// Another Example
string firstname = "Sourabh";
string lastname = " Chauhan";
string fullname = String.Concat(firstname,lastname);
//Output Will Be "Sourabh Chauhan"
Comments