The difference between String.Empty and string.Empty

I want to know what is the difference between them and what is the possible way to use them.

+3
source share
5 answers

Absolutely no difference. Even at the level of IL. In C #, it stringis an alias of the actual System.String.NET type. As for possible use, use it when you want to present an empty string in your application. There was a lot of discussion about the difference between string.Emptyand "", and the general consensus is that you should use the one that suits you best and make your code more readable, which is obviously subjective.

+21
source

No difference. stringis an aliasSystem.String

+2
No difference, it’s just predefine text or name for compiler.

string =String (class)
int =Int32 (struct)
long= Int64 (struct)
decimal = Decimal (struct)

String .

+1

Just FUI: There is one difference between aliases - Int32 and int, for example:

You can write:

enum A : int
{
}

But you cannot write:

enum A : Int32
{
}
0
source

As far as I know, there is no difference. At least no difference in results.

You may use it like this:

string mystring = "blah";

mystring = string.Empty;

or

String mystring = "blah";

mystring = String.Empty;
-1
source

Source: https://habr.com/ru/post/1766333/


All Articles