Difference in event subscription formatting

前端 未结 1 902
半阙折子戏
半阙折子戏 2020-12-12 04:22

Is there a difference between these two formats for subscribing to events:

Style 1:

foo.BarEvent += FooEventMethod;

Style 2:

<
相关标签:
1条回答
  • 2020-12-12 05:15

    This is c# 1.0 style of subscribing an event.

    foo.BarEvent += new FooEventHandler(FooEventMethod);
    

    Starting from c# 2.0 you're allowed to subscribe event like this

    foo.BarEvent += FooEventMethod;
    

    above code is exactly equal to version1 code, what happens is compiler will create new FooEventHandler(FooEventMethod) in background for you.

    0 讨论(0)
提交回复
热议问题