Is there a difference between these two formats for subscribing to events:
Style 1:
foo.BarEvent += FooEventMethod;
Style 2:
foo.BarEvent += new FooEventHandler(FooEventMethod);
See Question&Answers more detail:osIs there a difference between these two formats for subscribing to events:
Style 1:
foo.BarEvent += FooEventMethod;
Style 2:
foo.BarEvent += new FooEventHandler(FooEventMethod);
See Question&Answers more detail:osThis 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.