The Union method or operator is used to combine multiple collections or lists into a single collection or list and return collection with unique elements.
Syntax
var result = collection1.Union(collection2)
Example
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<string> count1= new List<string>() { 'UK', 'Australia', 'India', 'USA' };
List<string> count2 = new List<string>() { 'India', 'UAE', 'Canada', 'UK', 'China', 'Pok' };
List<string> list = count1.Union(count2).ToList();
list.ForEach( country => Console.WriteLine(country) );
Console.ReadLine();
}
}
Output
UK
Australia
India
USA
UAE
Canada
China
Pok
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The Union method or operator is used to combine multiple collections or lists into a single collection or list and return collection with unique elements.
Syntax
Example
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { List<string> count1= new List<string>() { 'UK', 'Australia', 'India', 'USA' }; List<string> count2 = new List<string>() { 'India', 'UAE', 'Canada', 'UK', 'China', 'Pok' }; List<string> list = count1.Union(count2).ToList(); list.ForEach( country => Console.WriteLine(country) ); Console.ReadLine(); } }Output