Ads

C# Programming 9 - What is the difference between String and string?

Hi All,

Welcome, 

Yes absolutely we are in right place. In this article we will look into the million-dollar question that's!!!! the difference between String and string.



Is there any difference between String and string?

Yes, of course we have! when you use String you should import the namespace System.String.

Joke part.😄

If we see technically, there is no difference. string is an alias in C# for System.String. 

String stands for System.String and it is a .NET Framework Class Library type. string is an alias in the C# language for System.String. Both of them are compiled to System.String in IL (Intermediate Language)

There are other aliases for C# data types shown below:

bool: System.Boolean
object: System.Object
byte: System.Byte
short: System.Int16

Please remember string is keyword and System.String is FCL(Framework Class Library) Type.

Another interesting thing is string is basically reserved keyword, but String is just a class name. So we cannot use string as a variable name by itself. But String we can. Please find below

StringBuilder String = new StringBuilder();  //Get  compiles without any issues
StringBuilder string = new StringBuilder();  // It doesn't compile 



We have got cleared about string and String, now question is when to use "String" and "string"?

Answer is very simple when you are doing variable declaration then use "string" (small "s" one) 

for integer case instead of using Int32 we use int.

Use String when you call any string functions.

string fullName = String.Empty;

I hope you enjoyed this article. That's it for right now, see you in next article until then take care bye bye 😄

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !