string.IsNullOrEmpty() vs string.NotNullOrEmpty()

前端 未结 14 971
遇见更好的自我
遇见更好的自我 2021-02-01 02:56

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

e.g.

if (!string.IsNullOrEmpty())
14条回答
  •  爱一瞬间的悲伤
    2021-02-01 03:35

    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);
    }
    

提交回复
热议问题