I have a string that may have whitespace characters around it and I want to check to see whether it is essentially empty.
There are quite a few ways to do this:
myString.Trim().Length == 0 Took : 421 ms
myString.Trim() == '' took : 468 ms
if (myString.Trim().Equals("")) Took : 515 ms
if (myString.Trim() == String.Empty) Took : 484 ms
if (myString.Trim().Equals(String.Empty)) Took : 500 ms
if (string.IsNullOrEmpty(myString.Trim())) Took : 437 ms
In my tests, it looks like myString.Trim().Length == 0 and surprisingly, string.IsNullOrEmpty(myString.Trim()) were consistently the fastest. The results above are a typical result from doing 10,000,000 comparisons.