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.

Advertisements