Get Unique value from two array

Write a program to get unique value from two array.


For Example:

Input:
Arr1= {“Mumabi”,”Pune”,”Delhi”,”Nagpur”}
Arr2= {“Kolkata”,”Patana”,”Pune”,” Mumabi”}

Output:
Arr = Kolkata, Patana, Delhi, Nagpur

Solution:

using System;
using System.Linq;

namespace ArrayOperation
{
    class Program
    {
        static void Main()
        {

            var arr1 = new[] { "Mumabi", "Pune", "Delhi", "Nagpur" };
            var arr2 = new[] { "Kolkata", "Patana", "Pune", "Mumabi" };

            var result = arr2.Except(arr1).ToList();
            result.AddRange(arr1.Except(arr2));

            Console.WriteLine($"Unique value from both array\n{string.Join(", ", result)}");
            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *