Should I prefer static methods in C#

前端 未结 6 1337
一整个雨季
一整个雨季 2021-02-05 08:47

Having spent a bit of time learning about functional programming, it\'s becoming more and more natural for me to want to work with static methods that don\'t perform any mutatio

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 09:05

    Great question.

    I think the answer depends on the context of what your code does, and how much of it is static.

    My code has been seeing less static cases since I program to interfaces a lot now and mark some methods 'protected virtual' rather than 'static' for cases such as unit testing's extract and override pattern. Thats not to say you couldnt just call static methods from those, though.

提交回复
热议问题