Friday, February 6, 2015

String.Empty vs. "" ?

I've researched this topic more than I would like to admit.  I think it is one of those things where I needed to find the correct answer so I can explain why to use one over the other or maybe it is just my OCD kicking in.  What I do know is that there are others like me.  This question is asked many times with the same answers over and over.

Below are some common responses to the question:

  • It is more efficient
  • It creates an object
  • It is more readable
  • It turns into better IL code
  • It is easier to type
  • It is easier to understand for newbies
  • It can be used in a switch statement 
  • It ...
My conclusion to my extensive research is that it doesn't matter.  Performance is not an issue when using either in a real life application.  When you are looking at code and come across this, don't change "" to string.empty or vice versa.  You are wasting your time and adding history to a file that does not need to be there.  You are not following the Boy Scout Rule because the file is not in a better place than you left it, it is in the same place. 

I am open to hearing thoughts on this to feed my OCD, but from everything that I have read I don't think there is anything new that would support one being so much better over the other.  It has been and still is in my category of personal preference.

peace yo!