👉🏼 Click here to Join I ❤️ .NET WhatsApp Channel to get 🔔 notified about new articles and other updates.
Using LINQ Concat to combine data

Using LINQ Concat to combine data

LINQ

26 Articles

Improve

In this article, let's learn about how to use Concat in LINQ in .NET.

Note: If you have not done so already, I recommend you read the article on Using LINQ Union to combine data.

Table of Contents

  1. Introduction
  2. Using LINQ Concat to combine primitive types
  3. Using LINQ Concat to combine with Equality Comparer
  4. Summary

Introduction

When working with two collections, we can combine them using LINQ Concat() method. This will combine two collections and gives a single collection with duplicates.

LINQ Concat() is used to answer questions about collection such as

  • Combining multiple data set from different sources for analysis
  • Git merge and combine files with changes from both commits
  • Append lines to files

Using LINQ Concat to combine primitive types

Primitive data types like int, decimal, string, etc can just compare the values against other value in the collection

Code Sample - LINQ Concat Primitive Types

Demo Space

Using LINQ Concat to combine with Equality Comparer

So, combining primitive data types with Concat() is easy and straight forward. The same goes with objects. There is no need for comparer as Concat() is going to simply combine without comparing.

Code Sample - LINQ Concat Product Comparer

Code Sample - LINQ Concat With Product Comparer

Demo Space

Summary

In this article we learn't how to combine data between collections using Concat. This can be used to combine items between collection and return a unified collection with duplicates. All these can be used with any IEnumerable or IQueryable types.

👉🏼 Click here to Join I ❤️ .NET WhatsApp Channel to get 🔔 notified about new articles and other updates.
  • LINQ
  • Concat
  • Concatenate
  • Combine
  • Duplicate