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

2
  • Google would be a good way to find this difference very easily. Or the search function here stackoverflow.com/questions/263191/… Commented Apr 11, 2013 at 3:34
  • they are just the same.String is the actual class and the keyword string just maps to the class String Commented Apr 11, 2013 at 3:35

4 Answers 4

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
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.