tags:

views:

72

answers:

1
+5  A: 

In C# 1.x only the second version would compile.

C# 2.0 added implicit method group conversions which allows you to write the first version. The two are equivalent. Sometimes it is necessary to use the more explicit form in the case that there is ambiguity.

See the section Delegate inference from Jon Skeet's article Delegate changes for more information.

Mark Byers
I think I'd call it method group conversions rather than delegate inference these days, admittedly :) Some time I must update that article...
Jon Skeet
@Jon Skeet: I checked and "method group conversions" is also what it is called in the What's New in C# 2.0 (http://msdn.microsoft.com/en-us/library/7cz8t42e%28VS.80%29.aspx). Thanks for the correction. I hope that your article is updated soon!
Mark Byers
@Jon Skeet : thanks Mr.Jon for your benefit topic :) , when I read it , I know what is the benefit of "event " (add/remove) but when I declare (add/remove) I can't call the event , in this case the event will be able to appear just on the left hand side of += or -= , How can I rais my event in this case ??
Farah_online
@Farah_online: You don't call the event - you use the underlying delegate field which you're using to keep track of the handlers added and removed.
Jon Skeet