Why can't I put a delegate in an interface?

前端 未结 7 1021
清歌不尽
清歌不尽 2021-02-01 03:24

Why can\'t I add a delegate to my interface?

7条回答
  •  一生所求
    2021-02-01 04:20

    The documentation clearly says that you can define a delegate in an interface:

    An interface contains only the signatures of methods, delegates or events.

    MSDN: interface (C# Reference)

    However, in the remarks on the same page it says that an interface can contain signatures of methods, properties, indexers and events.

    If you try to put a delegate in an interface, the compiler says that "interfaces cannot declare types."

    The Ecma-334 standard (8.9 Interfaces) agrees with the remarks on that page and the compiler.

提交回复
热议问题