Click here to Skip to main content
13,145,603 members (39,559 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 30 Oct 2012

Concat() vs Union()

, 30 Oct 2012
Rate this:
Please Sign up or sign in to vote.
Concat() vs Union()

Recently I worked with the two method on my enumeration object that are Union() and Concat(). This methods used to mostly used by developer to combine two collection in single collection, but that's not true here in this post I am going to show the actual difference between this two methods.

Def. from MSDN

Enumerable.Concat<tsource>  - Concatenates two sequences.

Enumerable.Union<tsource>    - Produces the set union of two sequences by using the default equality comparer.
If you read the def. carefully you actually find difference between two methods.

Now to understand it better way have look to below example

int[] ints1 = { 1, 2, 3 };
int[] ints2 = { 3, 4, 5 };
IEnumerable<int> union = ints1.Union(ints2);
foreach (int num in union)
   Console.Write("{0} ", num);
IEnumerable<int> concat = ints1.Concat(ints2);
foreach (int num in concat)
   Console.Write("{0} ", num);


The output shows that

Concat() method just combine two enumerable collection to single one but doesn't perform any operation/ process any element just return single enumerable collection with all element of two enumerable collections.

Union() method return the enumerable collection by eliminating the duplicate i.e just return single element if the same element exists in both enumerable collection on which union is performed.

Important point to Note

  • By this fact we can say that Concat() is faster than Union() because it doesn't do any processing. 
  • But if after combining two collection using Concat() having single collection with too many number of duplicate element and if you want to perform further operation on that created collection takes longer time than collection created using Union() method, because Union() eliminate duplicate and create collection with less elements.  


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pranay Rana
Software Developer (Senior) GMind Solusion
India India

Microsoft C# MVP (12-13)

Hey, I am Pranay Rana, working as a ITA in MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.

For me def. of programming is : Programming is something that you do once and that get used by multiple for many years

You can visit my blog

StackOverFlow -
My CV :-


You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 31 Oct 2012
Article Copyright 2012 by Pranay Rana
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid