Most efficient way to determine if a string length != 0?

Viewed 41494

I'm trying to speed up the following:

string s; //--> s is never null

if (s.Length != 0)
{
   <do something>
}

Problem is, it appears the .Length actually counts the characters in the string, and this is way more work than I need. Anybody have an idea on how to speed this up?

Or, is there a way to determine if s[0] exists, w/out checking the rest of the string?

9 Answers
String.IsNullOrWhiteSpace(s);

true if s is null or Empty, or if s consists exclusively of white-space characters.

Related