Array of LINQ operations (intersection, union, difference set, maximum value, average, deduplication)

Source: Internet
Author: User

Arrays are often used in universities.AlgorithmExercise object. Some classic algorithms are very valuable, and they are useful for exams, installation, and interviews. But now is the Efficiency Era. programming focuses on production efficiency. using LINQ can makeProgramApe avoids writing some basic algorithms and focuses on business processing.

The following uses arrays as an example to describe some commonly used LINQ operations.

 Static   Void Main ( String [] ARGs ){ Int [] A = { 1 , 2 , 3 , 4 , 5 , 6 , 7 }; Int [] B = { 4 , 5 , 6 , 7 , 8 , 9 , 10 }; Int [] C = { 1 , 2 , 3 , 3 , 4 , 1 , 2 , 4 , 6 , 1 , 6 , 5 };
// Intersection VaR Fuck = A. Intersect (B );
// Union VaR Shit = A. Union (B );
// A does not have B VaR Diff1 = A. 0000t (B );
// B does not have VaR Diff2 = B. t ();
VaR Max = A. Max (); VaR Min = A. Min (); VaR AVG = A. Average (); VaR Dis = C. Distinct ();
Print (Fuck); print (shit); print (diff1); print (diff2); console. writeline (max); console. writeline (min); console. writeline (avg); print (DIS );
Console. readkey ();}
Private Static Void Print (ienumerable < Int > List ){ Foreach ( VaR Item In List) {console. Write (item + " " );} Console. writeline ();}
Copy code

There is a picture with the truth:

Some references:

Http://msdn.microsoft.com/zh-cn/library/bb397894.aspx

Http://msdn.microsoft.com/en-us/library/system.linq.enumerable.intersect.aspx

Original article: http://www.cnblogs.com/wyjexplorer/archive/2012/02/24/2366912.html

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.