Raise an event of a class from a different class in C#

后端 未结 12 894
庸人自扰
庸人自扰 2020-11-28 07:44

I have a class, EventContainer.cs, which contains an event, say:

public event EventHandler AfterSearch;

I have another class, EventRaiser.c

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 08:20

    You can write a public method on the class you want the event to fire from and fire the event when it is called. You can then call this method from whatever user of your class.

    Of course, this ruins encapsulation and is bad design.

提交回复
热议问题