How to add a delegate to an interface C#

前端 未结 6 1878
无人及你
无人及你 2021-01-30 07:42

I need to have some delegates in my class.

I\'d like to use the interface to \"remind\" me to set these delegates.

How to?

My class look like this:

6条回答
  •  半阙折子戏
    2021-01-30 08:47

    Jon Skeet's answer is right, I just want to add a note.

    Interfaces are not there for "reminding" you what to do, or what to include in your classes. Interfaces are means of abstraction, used in Object Oriented programming and design methods. Maybe you don't need an interface declaration at all, unless you want to see some concrete class instances as the interface elsewhere in your program (Abstraction).

    If you want to enforce some coding standards in your project, you may want to try using code analysis tools (like in Visual Studio) - They allow extensions, that you can incorporate to add you own code analysis rules.

    Using code analysis, if you "forget" to add the delegates (although I don't see the point of forgetting it, as if the delegate is not used, it's not needed) you'll get a warning / error.

提交回复
热议问题