关于 Delegate 和 Anonymous method

Jueyoung 2008-07-10 01:43:33
请教各位达人,


this.button1.Click += delegate(object sender, EventArgs e) { this.label1.Text = "Button1 was Clicked!"; };
this.button2.Click += new EventHandler(delegate(object sender, EventArgs e) { this.label1.Text = "Button2 was Clicked!"; });



这两个写法 有什么区别么?
...全文
46 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jueyoung 2008-07-10
  • 打赏
  • 举报
回复
谢谢两位。
结贴
fuadam 2008-07-10
  • 打赏
  • 举报
回复
第一种形式就是简化,编译器帮你做了 new EventHandler 让代码更简洁而已
Jueyoung 2008-07-10
  • 打赏
  • 举报
回复
如果没有区别的话, 那又该怎样理解两种不同的写法呢?
ericzhangbo1982111 2008-07-10
  • 打赏
  • 举报
回复
没有区别。
Chapter 1, Tasting Functional Style in C#, introduces the functional programming approach by discussing its concepts and the comparison between functional and imperative programming. We also try to refactor a simple imperative code into a functional approach. Chapter 2, Walkthrough Delegates, covers the definition, syntax, and use of delegates. We also discuss the variance of delegates and the built-in delegate. Chapter 3, Expressing Anonymous Methods with Lambda Expressions, walks us through the concept of delegates and uses it to create and use an anonymous method. After we dig through the anonymous method, we can transform it into a lambda expression and then apply it to functional programming. Chapter 4, Extending Object Functionality with Extension Methods, elaborates the benefits of using the extension method in functional programming. Before that, we discuss the use of the extension method and also discuss how to get this new method in IntelliSense. Also, we try to invoke the extension method from other assemblies. Chapter 5, Querying Any Collection Easily with LINQ, enumerates the LINQ operator provided by C# and compares the two LINQ syntaxes: Fluent Syntax and Query Expression Syntax. We also discuss deferred execution in the LINQ process. Chapter 6, Enhancing the Responsiveness of the Functional Program with Asynchronous Programming, covers asynchronous programming for the functional approach. It will explain the Asynchronous Programming Model and the Task-based Asynchronous pattern. Chapter 7, Learning Recursion, explains the advantages of recursion over the loop sequence. We also discuss direct and indirect recursion in this chapter. Chapter 8, Optimizing the Code Using Laziness and Caching Techniques, covers the technique used to optimize the code in the functional approach. We talk about laziness thinking and the caching technique in order to optimize our code. Chapter 9, Working with Pattern, covers the advantages of using patterns compared to conventional switch-case operations. We discuss pattern matching and monad in this chapter. We use the pattern matching feature, which is the new feature provided by C# 7. Chapter 10, Taking an Action in C# Functional Programming, walks us through developing functional code based on given imperative code. We use our learning in the previous chapter to create an application using the functional approach. Chapter 11, Coding Best Practice and Testing the Functional Code, explains the best practice in the functional approach, including the creation of an honest signature and dealing with the side-effects. We also separate the code into domain logic and mutable shell and then test it using unit testing.

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧