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 of null.

  • 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.


Popular posts from this blog

java - Cannot send AES encrypted messages of over 47 characters -

php - How to set default value of a select dynamically from database using smarty? -

telerik - Reformat image format in PDF -