Should I Create a New Delegate Instance?

前端 未结 2 1748
感情败类
感情败类 2020-12-19 04:02

What are the implications of doing this...

this.myButton.Click += new EventHandler(this.myButton_Clicked);

...versus this?

         


        
相关标签:
2条回答
  • 2020-12-19 04:34

    Yes, the second version makes the compiler create an implicit delegate, much like you can specify this.MyMethod instead of new Action(this.MyMethod) or new Action(() => this.MyMethod()).

    0 讨论(0)
  • 2020-12-19 04:43

    The 2nd syntax is a shortcut for the 1st one introduced in C# 2.0.

    http://www.developer.com/net/csharp/article.php/3103031/Working-with-Delegates-Made-Easier-with-C-20.htm

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