
- 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
What are union, intersect and except operators in Linq C#?
Union
Union combines multiple collections into a single collection and returns a resultant collection with unique elements
Intersect
Intersect returns sequence elements which are common in both the input sequences
Except
Except returns sequence elements from the first input sequence that are not present in the second input sequence
Example
class Program{ static void Main(){ int[] count1 = { 1, 2, 3, 4 }; int[] count2 = { 2, 4, 7 }; var resultUnion = count1.Union(count2); var resultIntersect = count1.Intersect(count2); var resultExcept = count1.Except(count2); System.Console.WriteLine("Union"); foreach (var item in resultUnion){ Console.WriteLine(item); } System.Console.WriteLine("Intersect"); foreach (var item in resultIntersect){ Console.WriteLine(item); } System.Console.WriteLine("Except"); foreach (var item in resultExcept){ Console.WriteLine(item); } Console.ReadKey(); } }
Output
Union 1 2 3 4 7 Intersect 2 4 Except 1 3
- Related Articles
- C# Linq Except Method
- C# Linq Intersect Method
- What are C operators and Punctuators?
- What are increment (++) and decrement (--) operators in C#?
- What are operators in JavaScript?
- What are the arithmetic and character operators in DBMS?
- What are JavaScript Operators
- What are Arithmetic Operators in JavaScript?
- What are Comparison Operators in JavaScript?
- What are Logical Operators in JavaScript?
- What are Assignment Operators in JavaScript?
- What are Conditional Operators in JavaScript?
- What are boolean operators in Python?
- What are multiplicative operators in C++?
- What are shift operators in C++?

Advertisements