This question already has an answer here:
i want to know what is the difference between them and what is the posiible way to use them
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.
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
No difference. string
is alias of System.String
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.
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
{
}
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;