差异事件订阅格式 [英] Difference in event subscription formatting
本文介绍了差异事件订阅格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有订阅事件这两种格式之间的差异:
样式1:
foo.BarEvent + = FooEventMethod;
风格2:
foo.BarEvent + =新FooEventHandler(FooEventMethod);
解决方案
这是C#1.0订阅事件的风格。
foo.BarEvent + =新FooEventHandler(FooEventMethod);
从的 C#2.0中你被允许订阅事件喜欢这个
foo.BarEvent + = FooEventMethod;
上面的代码是完全等于VERSION1代码,会发生什么情况是编译器将创建新FooEventHandler(FooEventMethod)
在后台为您服务。
Is there a difference between these two formats for subscribing to events:
Style 1:
foo.BarEvent += FooEventMethod;
Style 2:
foo.BarEvent += new FooEventHandler(FooEventMethod);
解决方案
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.
这篇关于差异事件订阅格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文