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.
using System; class Test { static void Main() { string s = "Technothirsty"; String t = "Technothirsty"; Console.WriteLine(s == t); // True Console.ReadKey(); } }
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.
class Test { static void Main() { system.String s = "Technothirsty"; string t = "Technothirsty";// Not allowed Console.ReadKey(); } }
Folks you should also refer below articles for better understanding of differences between:
- Difference between & and && ,| and ||
- Difference between Var and Dynamic in c#
- Difference between RegisterClientScriptBlock and RegisterStartupScript asp.net
- Difference between ref and out parameters in C#
- Difference between static and non-static variable in C#
- Difference between Abstraction and Encapsulation in C#
- Difference between Throw and Throw ex in C#
- Difference between Hashtable and Dictionary
- Difference between Nullable<> and ?
- Difference Between WCF and WebAPI