In LINQ, the Except method or operator is used to return only these elements from the first collection or list which are not present in the second collection or list. in another word first collection elements are doesn't present in the second collection then return the remaining first collection element.
Syntax
collection1.Except(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.Except(count2).ToList();
list.ForEach( country => Console.WriteLine(country) );
Console.ReadLine();
}
}
Output
Australia
USA
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.
In LINQ, the Except method or operator is used to return only these elements from the first collection or list which are not present in the second collection or list. in another word first collection elements are doesn't present in the second collection then return the remaining first collection element.
Syntax
Example
Output