Use Union operator in Linq.

We want to use Union operator in Linq.  How to use this please help me.
Last updated:3/20/2016 11:05:36 PM

1 Answers

Aditya Patel
Aditya Patel

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)