Which is better – “” or string.Empty ?

Answer is string.Empty. Now you may ask, why?
OK. The answer to your WHY is – string is immutable i.e when we want to change a value, stored in a string variable, it creates a new copy in the memory and then the old memory space hold by that string variable is released by garbage collector.
Above process is followed when we do things like-
string str= “”;
But, in case of string str=string.Empty;
it doesn’t create a new copy.
So, avoid string assignment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s