Refer to 30 minutes to learn LINQ:
Http://www.cnblogs.com/liulun/archive/2013/02/26/2909985.html
Three generic delegates:
// predicate 1,bool type return value; 2, only 1 parameters var wt1 = new predicate <int > (more); // action 1, no return value; 2, multiple parameters var wt2 = new action<< Span style= "color: #0000ff;" >int , string > (Voidmethod); // func 1, the last one is the return value 2, multiple arguments var wt3 = int , string , string > ( Stringmethod);
Explain the lambda expression:
//lambda expressionlist<int> arr =Newlist<int> () {1,2,3,4,5,6,7};arr. ForEach (Newaction<int> (Delegate(inta) {Console.WriteLine (a);})); Arr. ForEach (Newaction<int> (A =Console.WriteLine (a)));//Here's an explanation of this lambda expression//< 1 > A is an input parameter, and the compiler can automatically infer what type it is,//If there is no input parameter, it can be written like this: () = Console.WriteLine ("DDD")//< 2 > = is the lambda operator//< 3 > Console.WriteLine (a) is the statement to execute. If it is more than one statement, you can use {} to wrap it up. If you need to return a value, you can write the return statement directly
Finally, LINQ, two common query operators:
Where Condition filter, select conditional projection
Where: You need to pass a func (type,bool) generic delegate, the following example is List<int>, so type = Int. The same is true for select.
select****//each element +1list<int> AA =Newlist<int> () {1,2,3,4};ienumerable<int> aanew = aa. select<int,int> (A = a +1);//Add a weather to the front of each elementlist<string> SS =Newlist<string> () {"Ice","Kindle"," Wind","Snow"};ienumerable<string> ssnew = ss. select<string,string> (v ="Weather"+v);where****//filter out the elements of a>3list<int> arr =Newlist<int> () {1,2,3,4,5,6,7 };varA = arr. Where (A + = {returnA >3; });
C#-linq