Although I have intermediate knowledge of asp.net & C#, but I am still not clear with what's the difference between String (capital S) and string in C#?
When to use which one?
string name="Pika"; String name ="Pika";
In simple, there is no difference between string and String. string is a alias created by Microsoft for System.String.
As we go into details, you can see these difference between them:
Stringwhen using the static methods on the String class, like
stringto declare types - variables, properties, return values and parameters. This is consistent with the use of other system types -
Booleanare also correct).
"string" keyword is an alias for System.String in the .NET, that means the String and string are equal, you can either one of them while writing code in C#
Syetem.String and string are compiled to System.String in Intermediate Language (IL), so the performance of both is also same, it just depends on your choice, which one to use.
stringwhile referring to an object.
Stringwhile referring to the class.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly