1

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

enter image description here

  • 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 Answers4

5

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
John Woo
  • 238,432
  • 61
  • 456
  • 464
4

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.

KF2
  • 8,889
  • 8
  • 37
  • 76
2

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.

jacob aloysious
  • 2,177
  • 11
  • 15
1

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

Phong Vo
  • 1,010
  • 7
  • 15