Is extending String class with IsNullOrEmpty confusing?

后端 未结 12 2015
有刺的猬
有刺的猬 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 02:20

    Calling a method on a variable that is null usually results in a NullReferenceException. The IsNullOrEmpty()-Method deviates from this behaviour in a way that is not predictable from just looking at the code. Therefore I would advise against using it since it creates confusion and the benefit of saving a couple of characters is minimal.

提交回复
热议问题