This is mainly for programmers who have studied C # 2.0, if they already know what an anonymous method is. If it is not clear, please read "Serial: C # 2.0 Primer" (This will be translated in the future).
OK, let's get to the point.
A lambda expression (a lambda expression), interpreted in one sentence, is (not very rigorous) the syntax for making anonymous method text shorter. Even so, the idea that single "is merely a textual change and the nature of the source code has not changed" is a misconception. The scale changes and its nature changes. For example, the phenomenon produced in a beaker of a laboratory is not necessarily produced in a large factory. The same principle applies to source code.
So, just experience the lambda expression.
The following, using specific code to illustrate, is not the actual project code, but the actual use of C # 2.0 rewrite.
A while ago I actually wrote the code, there is a menu, can choose the Pull-down menu. menu items are defined as follows:
1public delegate bool SimpleMenuAction();
2
3public class MenuItemA // 菜单项
4{
5 public readonly string Name; // 名字
6 public readonly SimpleMenuAction Action; //执行内容
7
8 public MenuItemA(string name, SimpleMenuAction action)
9 {
10 Name = name;
11 Action = action;
12 }
13}
14
List 1 Definition of menu item
In contrast, the following is an array of menu items.
1private static MenuItemA[] Menu Items1 =
2 {
3 new MenuItemA("选择项1", 执行方法),
4 new MenuItemA("选择项2", 执行方法),
5 new MenuItemA("选择项3", 执行方法),
6 };
7