What is the difference between string.Empty and String.Empty in C#? Also note the colors are different. They both reference or are of type class System.String
-
Google would be a good way to find this difference very easily. Or the search function here http://stackoverflow.com/questions/263191/in-c-should-i-use-string-empty-or-string-empty-or?rq=1 – PW Kad Apr 11 '13 at 03:34
-
they are just the same.String is the actual class and the keyword string just maps to the class String – Prabhu Murthy Apr 11 '13 at 03:35
4 Answers
It is the same. string
is an alias of class System.String
.
some common aliases:
object ==> System.Object
string ==> System.String
bool ==> System.Boolean
int ==> System.Int32
float ==> System.Single
double ==> System.Double
decimal ==> System.Decimal
char ==> System.Char

- 258,903
- 69
- 498
- 492
String.Empty
and string.Empty
are same. String
is the BCL class name. string
is the C#...shortcut if you will. Same as with Int32 and int.

- 9,887
- 8
- 44
- 77
Both are SAME except that string
is treated as a keyword
with Blue
color (default) and System.String
is a Class
with Green
Color (default) in the VS editor.
Underlying implementation are all the same. In other words points to the same.

- 2,547
- 15
- 16
In C#, the string keyword is an alias for String. Therefore, String and string are equivalent, and you can use whichever naming convention you prefer. The String class provides many methods for safely creating, manipulating, and comparing strings. In addition, the C# language overloads some operators to simplify common string operations

- 1,078
- 7
- 16