USE UNION OPERATOR IN LINQ.

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
LINQ 
 527  View(s)
Ratings:
Rate this:
We want to use Union operator in Linq.  How to use this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: Use Union operator in Linq.

    The Union extension method requires two collections, one collection on which the Union method is invoked and a second collection,
     which is passed as a parameter. The Union method returns distinct elements from both the collections.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    namespace Prototype

    {

    class Example

    {

    static void Main()

    {

    IList<string> List1 = new List<string>() { "aditya", "manoj", "komal", "karan", "tarun" };

    IList<string> List2 = new List<string>() { "tarun", "ajay", "vimal", "vijay", "manoj" };

    var result = List1.Union(List2);

    foreach (string str in result)

    Console.WriteLine(str);

    Console.ReadLine();

    }

    }

    }

Answer

NEWSLETTER

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