What is the difference between String (capital S) and string in C#?


Difference between upper and lower case string: Here in this article will see the difference between String (Capital S) and string (small s) in C#. The short and direct answer to this question is both String and string are the same and there is no difference between them. The string is nothing but an alias in the C# language for System.String.

We can also say that String is a short version of System.String and string is the C# abbreviation for String. Similarly, like int is for System.Int32 and short is for System.Int16

String and string both of them are get compiled into System.String in Intermediate Language, hence there is no difference between them. 

But yes there is one restriction with lower case string. As the string is a reserved keyword hence we cannot use it as a variable name, whereas String (Capital S) can be used as a variable.

Below Code :

string String = "Hello World";  // compiles
string string = "Hello World";  // gives error doesn't compile 

When to use String and string in C#?

Well, it's generally recommended to use an alias if we have to declare a variable.

string blogName = "Codepedia";

And use Upper case String, if want to use a built-in method like String.IsNullOrEmpty, String.Format , String.Equal and so on.


Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.

PS: If you found this content valuable and want to thank me? 👳 Buy Me a Coffee

Subscribe to our newsletter

Get the latest and greatest from Codepedia delivered straight to your inbox.

Post Comment

Your email address will not be published. Required fields are marked *