HOW TO USE EXCEPT KEYWORD IN LINQ QUERY.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#  LINQ 
 482  View(s)
Ratings:
Rate this:
I want to use Except keyword in linq query. How to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use Except keyword in linq query.

    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)
                    Console.WriteLine(str);

                Console.Read();
            }
        }
    }

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!