Introduction
In this article I will explain the difference between string and String in c# as well as the guidelines for the use of each. Many times i got this questions from my junior's who working with me in my organization as well as developers who is beginner in the IT sector, There are many articles related this question already available in the internet, but in this article I will explain difference between string and String in c# with example. So it would be more helpful to understand for students as well as beginner developers.
Requirement
What is string?
Differentiate between string and String in C# with example.
Implementation
What is string?
As per the C# programming guideline provided by Microsoft, a string is an object of type String whose value is plain text, or it is a sequential collection of characters.
string Vs. String
In the C#, the keyword string is an alias of String. So, string and String both are equivalent and technically, there is no difference.
I recommended to use string when you're referring to an object.
Example
string _value = "Nikunj Satasiya";
And I recommended to use String or System.String while you referring specifically to the class, and want you use any method available in the String class.
Example
string _value = String.Format("Hi, {0}", username);
if (String.IsNullOrEmpty(username)) { }
Summary
In this article, we learned there is no differentiate between string and String in C# and both are equivalent.