What is the difference between String and string in C#?

Post author: Adam VanBuskirk
Adam VanBuskirk
5/13/23 in
Tech
C#

string s = "Hello world!";
String s = "Hello world!";

The Answer

There is no difference. String represents System.String which is a .NET Framework type. string is an alias for the System.String. Both are compiled to the System.String in the intermediate language. It’s proper to use whichever version you prefer, but below are a few best practices.

When working with or using as an object, use the lowercase string version

string place = "world";

When working with the class, use the uppercase String version

string greet = String.Format("Hello {0}!", place);

Sign up today for our weekly newsletter about AI, SEO, and Entrepreneurship

Leave a Reply

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


Read Next




© 2024 Menyu LLC