事件订阅格式的差异 [英] Difference in event subscription formatting

查看:7

问题描述

这两种订阅事件的格式有区别吗:

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

样式一:

foo.BarEvent += FooEventMethod;

样式 2:

foo.BarEvent += new FooEventHandler(FooEventMethod);

推荐答案

这是 c# 1.0 样式的订阅事件.

This is c# 1.0 style of subscribing an event.

foo.BarEvent += new FooEventHandler(FooEventMethod);

c# 2.0 开始,您可以订阅事件,例如这个

foo.BarEvent += FooEventMethod;

上面的代码完全等于version1的代码,编译器会在后台为你创建new FooEventHandler(FooEventMethod).

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆