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

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo