Wednesday, November 11, 2015

Difference between "string" and "String" in C#


Hello Folks !

Many times while writing some cool code, you also may have come across this question in your mind and it may have kept you bemused and thinking. So, let's understand the difference between the both.
string s = "Hello world";
String s = "Hello world";
Technically, there's no difference between the two. As far as the syntax is concerned it is recommended to use string whenever you're referring to an object.

string s = "Hello world"
Likewise, it is recommended to use String to call string methods like String.Format(), String.IsNullOrEmpty()


bool x = String.IsNullOrWhiteSpace(txtName.Text)

I hope that makes sense, because methods belong to classes and it is consistent with how other static methods are called.

No comments :

Post a Comment