Recipe 2.24. Testing a String for Null or EmptyProblemYou need a quick and easy way to check if a string is either null or of zero length. SolutionUse the static IsNullOrEmpty method of the String class: bool stringTestResult = String.IsNullOrEmpty(testString); DiscussionThe 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 AlsoSee the "String.IsNullOrEmpty Method" topic in the MSDN documentation. |