string.IsNullOrEmpty() vs string.NotNullOrEmpty()

前端 未结 14 1202
遇见更好的自我
遇见更好的自我 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:33

    For those logicians out there, !string.IsNullOrEmpty is not equivalent to string.IsNotNullOrEmpty. @Guffa has it correct. Using DeMorgan's law, it would have to be string.IsNotNullAndNotEmpty to be equivalent.

    ¬(null ∨ empty) ⇔ ¬null ∧ ¬empty

    ¬(null ∨ empty) ≠ ¬null ∨ empty

    The point here, I guess, is that the way it is currently is unambiguous, where as making the opposite unambiguous would be cumbersome.

提交回复
热议问题