Use Union operator in Linq.

Total Post:45

Points:315
LINQ 
 856  View(s)
Ratings:
Rate this:
We want to use Union operator in Linq.  How to use this please help me.
  1. Post:281

    Points:2003
    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();

    }

    }

    }

      Modified On Apr-11-2018 02:20:38 AM

Answer