class Program
{
static void Main(string[] args)
{
string [] strings= new string[]{"James","Kavin","Robin","Anna"};
string [] strings2= new string[]{"James","Peter","Patrick","Michael"};
//Produces the union of two sequences by using the default equality comparer.
IEnumerable<string> combined = strings2.Union(strings);
foreach (var str in combined)
{
Console.WriteLine(str);
}
Console.WriteLine("\n######################## Linq way ####################");
//remove duplicates using Linq
var result = strings.Concat(strings2).GroupBy(s => s).Select(x => x.First());
foreach (var str in result)
{
Console.WriteLine(str);
}
Console.ReadKey();
}
}Sometimes we need to combine two arrays and eliminate any duplicates among them. We can either use union method from string class which uses default comparator or linq query.
