Home > DeveloperSection > Forums > How to use Except keyword in linq query.
Ankit Singh

Total Post:341

Posted on    January-21-2016 10:05 PM


 1 Reply(s)
 439  View(s)
Rate this:
I want to use Except keyword in linq query. How to do this please help me.

aditya kumar Patel

Total Post:254

Posted on    January-21-2016 10:09 PM

The Except() method requires two collections.
One collection on which Except method invoked and second collection which is passed as a parameter.
The Except method returns the elements from first collection which do not exist parameter in the second collection.

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace program
    class Example
        public static void Main()
            IList<string> List1 = new List<string>() { "aditya", "manoj", "kavita", "komal", "vimal" };
            IList<string> List2 = new List<string>() { "aditya", "sohel", "vimal", "mayank", "mohit" };

            var result = List1.Except(List2);
            Console.BackgroundColor = ConsoleColor.Red;
            Console.ForegroundColor = ConsoleColor.White;
            foreach (string str in result)


Modified On Jan-21-2016 10:11:18 PM

Don't want to miss updates? Please click the below button!

Follow MindStick