Alex Rivera | Logout

string.IsNullOrEmpty() vs string.NotNullOrEmpty()

Asked 2009-04-09T13:58:03.567
34

I'm curious if any developers use string.IsNullOrEmpty() more often with a negative than with a positive

e.g.

if (!string.IsNullOrEmpty())

This is how I use the method 99% of the time. What was the design decision for this?

Edit
Report

1 Answer

9

I always create an extension method for "HasContent()" which generally makes sense, follows the "positive" specifications, and saves on code bloat because I use it much more often than its counterpart:

public static bool HasContent(this string s) {
    return !string.IsNullOrEmpty(s);
}
answered 2010-04-27T13:37:30.643

Your Answer