Is extending String class with IsNullOrEmpty confusing?

后端 未结 12 2024
有刺的猬
有刺的猬 2020-12-06 01:40

Everyone knows and love String.IsNullOrEmpty(yourString) method.

I was wondering if it\'s going to confuse developers or make code better if we extend String class t

12条回答
  •  广开言路
    2020-12-06 02:25

    I think extending any object with an "IsNull" type call is a little confusing and should be avoided if possible.

    It's arguable that the IsEmptyString method might be useful for the String type, and that because you'd usually combine this with a test for null that the IsNullOrEmpty might be useful, but I'd avoid this too due to the fact that the string type already has a static method that does this and I'm not sure you're saving yourself that much typing (5 characters at most).

提交回复
热议问题