Recipe 2.24. Testing a String for Null or Empty
Problem
You need a quick and easy way to check if a string is either null or of zero length.
Solution
Use the static IsNullOrEmpty method of the String class:
bool stringTestResult = String.IsNullOrEmpty(testString);
Discussion
The IsNullOrEmpty method is a very convenient method in that it allows you to test a string for null or zero length with a single method call. This method returns true if the string passed in to it is equal to one of the following:
Otherwise, this method returns false.
See Also
See the "String.IsNullOrEmpty Method" topic in the MSDN documentation.
|