c# - is string variable and string variable with string.empty same? -
i have many scenarios in application declaring strings string.empty , later dynamically adding values it. in c#,
string status
and
string status = string.empty;
same?
those lines of code not equivalent.
if you've declared
string status
outside of method, initializes default value ofnull
.if you've declared
string status
inside method, isn't initialized, , can't use until explicitly give value.
whether or not need string status = string.empty;
depends on situation, seems decent way of avoiding nullreferenceexception
if find code throws.