[C # 3.0 Getting Started] [Chapter One lambda expression] section II: What does a lambda expression bring

Source: Internet
Author: User
Tags anonymous

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.