In C# why can't I pass another class' EventHandler reference and how can I get around it?

后端 未结 3 1396
醉话见心
醉话见心 2020-12-31 12:37

If I have ClassA that has a public event, SomeEvent, and ClassC that has method, addListener, that accepts an EventHandler reference, why can\'t ClassB have a line that says

3条回答
  •  無奈伤痛
    2020-12-31 13:22

    How can I get around it while staying reasonably close to my structure?

    Use a.SomeEvent += handler instead.

    Why does this restriction exist?

    See Marc Gravell's answer.

提交回复
热议问题