Why shouldn't C#(or .NET) allow us to put a static/shared method inside an interface?

后端 未结 7 1857
无人及你
无人及你 2020-12-11 04:24

Why shouldn\'t C#(or .NET) allow us to put a static/shared method inside an interface?

seemingly duplicate from here. but my idea is a bit different one, I just wan

相关标签:
7条回答
  • 2020-12-11 05:15

    An interface's purpose is to declare an object's interface through which it can be accessed. Due to the fact that this is its sole purpose, it would not make sense to allow code being placed in an interface. If you still want to add some code to an interface, you could use extension methods.

    0 讨论(0)
提交回复
热议问题