Question

Is there any difference whether I use string or String in my C# code?

Or does the compiler map one to another?

1 Answers

Technically, there is no difference between them. string is simply an alias for System.String. Both of them compile to System.String.

Look at the Microsoft examples and try to follow the same conventions. Here are a few examples that I have taken from the msdn:

Example 1: Use string if you need to refer to its object.

string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b = s1.Contains(s2);

Example 2: Use String if you need to refer specifically to the class itself.

Decimal pricePerOunce = 17.36m;
String s = String.Format("The current price is {0} per ounce.",pricePerOunce);