
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to find Union of two or more Lists
Firstly, create lists −
//three lists var list1 = new List{3, 4, 5}; var list2 = new List{1, 2, 3, 4, 5}; var list3 = new List{5, 6, 7, 8};
Use the union method to get the union of list1 and list2 −
var res1 = list1.Union(list2); var res2 = res1.Union(list3);
The following is the complete code −
Example
using System.Collections.Generic; using System.Linq; using System; public class Demo { public static void Main() { //three lists var list1 = new List<int>{3, 4, 5}; var list2 = new List<int>{1, 2, 3, 4, 5}; var list3 = new List<int>{5, 6, 7, 8}; // finding union var res1 = list1.Union(list2); var res2 = res1.Union(list3); foreach(int i in res2) { Console.WriteLine(i); } } }
Output
3
4
5
1
2
6
7
8
- Related Articles
- Python program to find Union of two or more Lists?
- C# program to find Union of two or more Dictionaries\n
- C# program to concat two or more Lists
- C# program to find common values from two or more Lists
- Program to find union of two given linked lists in Python
- C# program to find Intersection of two lists
- How to find the intersection between two or more lists in R?
- C++ program to find union and intersection of two unsorted arrays
- Program to find median of two sorted lists in C++
- C# program to find additional values in two lists
- Python program to find Intersection of two lists?
- Python program to find Cartesian product of two lists
- C program to perform union operation on two arrays
- C++ Program to Find the Shortest Supersequence that Contains Two or more Sequences as Subsequences
- Java Program to Calculate union of two sets

Advertisements