+= operator with Events

后端 未结 6 962
离开以前
离开以前 2020-11-28 09:50
public void Bar()
{
    Foo foo = new Foo();
    **foo.MyEvent += foo_MyEvent;**
    foo.FireEvent();        
}

void foo_MyEvent(object sender, EventArgs e)
{
    (         


        
6条回答
  •  甜味超标
    2020-11-28 10:47

    += subscribes to an event. The delegate or method on the right-hand side of the += will be added to an internal list that the event keeps track of, and when the owning class fires that event, all the delegates in the list will be called.

提交回复
热议问题