Is extending String class with IsNullOrEmpty confusing?

后端 未结 12 2010
有刺的猬
有刺的猬 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:19

    Personally, I wouldn't create an extension that does something that already exists in the framework unless it was a significant improvement in usability. In this instance, I don't think that's the case. Also, if I were to create an extension, I would name it in a way as to reduce confusion, not increase it. Again, I think this case fails that test.

    Having said all that, I do have a string extension that tests, not only if the string is null or empty, but also if it only contains whitespace. I call it IsNothing. You can find it here.

提交回复
热议问题