How to raise event using addHandler

后端 未结 4 670
轮回少年
轮回少年 2021-02-15 15:54

I am comfortable with Vb.Net events and handlers. Can anybody will help me with how to create event handlers in c#, and raise events.

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-15 16:22

    In C# 2 and up you add event handlers like this:

    yourObject.Event += someMethodGroup;
    

    Where the signature of someMethodGroup matches the delegate signature of yourObject.Event.

    In C# 1 you need to explicitly create an event handler like this:

    yourObject.Event += new EventHandler(someMethodGroup);
    

    and now the signatures of the method group, event, and EventHandler must match.

提交回复
热议问题