C#-linq

Source: Internet
Author: User

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

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.