Is There a Difference Between String and string in C#?

Technically there is  no difference  between String and string. If you declare two variables in the simple console application and open code in ILSpy you will see it points to the String class.

Visual Studio string declaration

Pic 1. String variable declaration – Visual Studio, Console Application


ILSpy String class

Pic 2. ILSpy – String class

When to Use Capitalized and Regular Declaration?

Usually, developers use  regular strings for variable or constant declarations. And capitalized String uses to get access for string functions like Format, Join , etc. But it is mostly a recommendation you can use both styles. Here are C# examples:

Capitalized and regular 
</a>String Declaration in C#”/></p><p>Capitalized and Regular string Declaration, Visual Studio</p> <span class= Keep in mind string is an alias in C# for System.String 

Leave a Reply

Your email address will not be published.