i want to know what is the difference between them and what is the posiible way to use them
5 Answers
Absolutely no difference. Not even at the IL level. In C# string
is an alias to the actual System.String
.NET type. As to the possible use, well, use it whenever you want to represent an empty string in your application. There have been many discussions as to what is the difference between string.Empty
and ""
and the general consensus is that you should use the one that suits you best and makes your code more readable which obviously is subjective.

- 1,023,142
- 271
- 3,287
- 2,928
-
9var s2 = String.Empty requires a import statement for "System". var s2 = string.Empty does not. Don't know why im mentioning it, =) – RPM1984 Sep 24 '10 at 06:37
-
2Oh and +1 for a good answer on a bad question. – RPM1984 Sep 24 '10 at 06:41
-
i hv seen ppl using string name= string.Empty and protected string _PK_ID=String.Empty why they are using this..... just for making code readable........... – user Sep 24 '10 at 06:43
-
@RPM1984, `string` is alias to `System.String`. That's why the import is required. Still no difference at the emitted IL by the compiler. – Darin Dimitrov Sep 24 '10 at 06:46
-
@user, I guess those are different people. Once you decide which one to use it would be better to be consistent over the whole application codebase. – Darin Dimitrov Sep 24 '10 at 06:47
-
i got your point but i hv seen it in a same code file....actually this particular question has been asked to me and i was not able to find any......anywaz thanks – user Sep 24 '10 at 06:54
-
1It used to be that using a reference to String.Empty was better than having many empty strings using "". Every time you created an empty string with "", it would allocate memory for the string, and it's already been allocated for String.Empty. These days however, the C# compiler automatically performs string interning, so it's not so bad. I still prefer the use of a named constant over a magic string though - so I always go for String.Empty. – Tim Roberts Sep 24 '10 at 07:45
-
@Tim - actually, string interning is a CLI offering, not a compiler one. – Marc Gravell Sep 24 '10 at 08:40
No difference. string
is alias of System.String

- 11,279
- 2
- 34
- 47
-
string is an alias for System.String in mscorlib. You can define your System.String in your assembly, but string will not change. – gandjustas Sep 24 '10 at 06:34
No difference, it’s just predefine text or name for compiler.
string =String (class)
int =Int32 (struct)
long= Int64 (struct)
decimal = Decimal (struct)
Compiler interpret as String class and others as relevant structure.

- 189
- 4
Just FUI: There is one difference between aliases - Int32 and int, for example:
You could write:
enum A : int
{
}
But you can't write:
enum A : Int32
{
}

- 8,364
- 7
- 43
- 90
As far as I know, there is no difference. Atleast, no difference in the outcome.
You may use it like this: string mystring = "blah"; mystring = string.Empty;
Or
String mystring = "blah"; mystring = String.Empty;