Differences between LINQ Concat Union intersect

Source: Internet
Author: User

Concat: concatenates two sequences. Http://msdn.microsoft.com/zh-cn/library/bb351755 (V = vs.90). aspx

Union: generate the union of two sequences by using the default equal comparator. Http://msdn.microsoft.com/zh-cn/library/bb341731 (V = vs.90). aspx

Intersect: the intersection of two sequences is generated by comparing values using the default equal comparator. Http://msdn.microsoft.com/zh-cn/library/bb460136 (V = vs.90). aspx

It can be understood as follows:

Assume there are two sequences:

VaR A = new list <int> {1, 1, 2, 3, 4 };
VaR B = new list <int> {4, 5, 5, 6, 7 };

A. Concat (B) means to concatenate sequence a and sequence B to create a new sequence without removing duplicates;

A. Union (B) indicates concatenating sequence a and sequence B, removing duplicates, and creating a new sequence;

While a. Intersect (B) only takes the same part (intersection) of Series A and Series B to create a new sequence.

ExampleCode:

Void main ()
{
VaR A = new list <int> {1, 1, 2, 3, 4 };
VaR B = new list <int> {4, 5, 5, 6, 7 };

Print (A. Concat (B). tolist ());
Print (A. Union (B). tolist ());
Print (A. Intersect (B). tolist ());

/*
* ******* A. Concat (B )************
1
1
2
3
4
4
5
5
6
7
*********************************

* ******** A. Union (B )***********
1
2
3
4
5
6
7
*********************************

* ******** A. Intersect (B )***********
4
*********************************
*/
}

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.