Lambda expression diagram, lambda expression

Source: Internet
Author: User

Lambda expression diagram, lambda expression

Internal delegate int MyDel (int x); public class Lambda {private MyDel del = delegate (int x) {return x + 1 ;}; // anonymous method private MyDel del2 = (int x) =>{ return x + 1 ;}; // Lambda expression private MyDel del3 = (x) ==>{ return x + 1 ;}; // Lambda expression private MyDel del4 = x => x + 1; // Lambda expression}

 


Where does the lambda expression come from?

Lambda Expressions (Lambda Expressions) 16: 33 Lambda Expressions (Lambda Expressions) and anonymous methods are actually one thing. The only difference is that their syntax format is different. Lambda expressions are further evolved in terms of syntax. In essence, they are one thing. Their role is to generate methods. That is, the inline method.

Reference from C # head Architect Anders Hejlsberg:

Www.ondotnet.com/..page%2

Lambda expressions and anonymous methods are really just two words for the same thing. The only thing that differs is, "What does the syntax look like? "And the lambda expressions are a further evolution of the syntax. But underneath, they do the same thing. They generate methods. You know, they're in-line methods.

Therefore, we should understand both the anonymous method and Lambda expression. Next, let's take a look at a simple code example, using anonymous methods and Lambda expressions to search for Arrays:

Use the. net 2.0 anonymous method to search for the string array containing

Static void Main (string [] args)
{
String [] list = new string [] {"abc", "12", "java "};
String [] ll = Array. FindAll (list,
Delegate (string s)
{
Return s. IndexOf ("a")> = 0;
}
);
Foreach (string var in ll)
{
Console. WriteLine (var );
}
Console. ReadLine ();
}

Use a. net 3.5 Lambda expression to search for a string array containing

Static void Main (string [] args)
{
String [] list = new string [] {"abc", "12", "java "};

String [] ll = Array. FindAll (list, s => (s. IndexOf ("a")> = 0 ));
Foreach (string var in ll) ...... remaining full text>

Who will explain the lambda expression in detail?

Simply put, it is an anonymous delegate.
See msdn
Msdn.microsoft.com/zh-cn/library/bb213687.aspx
Reference: msdn.microsoft.com/zh-cn/library/bb213687.aspx

Related Article

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.