C # Lambda expressions,
Lambda expressionsIt simplifies the use of anonymous delegation and makes the code more concise and elegant. It is said that it is one of the most important features added by Microsoft after c #1.0.
First, let's take a look at its development
According to the above development process, we can feel that Lambda expressions are more simplified.
Details:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Lambda{ class Program { static void Main(string[] args) { int sum = 0; Func<int, int> f1 = x => 2 * x + 1; Func<int, int, bool> f2 = (x, y) => x > y; Func<string, int, string> f3 = (x, y) => x.Substring(y); Func<int, int> f4 = (x) => sum += x; Action a1 = () => { System.Console.WriteLine("HelloWorld"); }; Action <int> a2 = (x) => { System.Console.WriteLine(x); }; Action <bool> a3 = (x) => { System.Console.WriteLine(x); }; Action<string> a4 = (x) => { System.Console.WriteLine(x); }; for (int i = 1; i <= 10; i++ ) { f4(i); } a2(sum); a1(); a2(f1(1)); a3(f2(3, 5)); a4(f3("Zhengpengfei", 5)); System.Console.Read(); } }}