• Rogue@feddit.uk
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    string.IsNullOrEmpty(myStr) has always annoyed me, why isn’t it an extension method or a non-static method?

    myStr.IsNullOrEmpty() just feels cleaner and more intuitive to me.

    • JakenVeina@lemm.ee
      link
      fedilink
      English
      arrow-up
      1
      ·
      6 months ago

      The usual convention is to have extension methods behave like regular methods, I.E. don’t allow them to accept nulls. When looking at foo.Bar(); it’s better if I can just intuit that foo can’t be null because you’re not supposed to be able to invoke the . operator on null.

      Of course, I’m entirely guilty of breaking this rule myself. cough Shoudly cough FluentAssertions cough