Except intersection of two arrays in c#

Hello Devs, this is the task recently I received from one of my colleague.

The Question is below

Two input Arrays

A = { “Blue”, “Green”, “Yellow”, “Red” }
B = { “Green”, “White”, “Red” }

Output should be like, The output collection should be sorted as well.
Output: {“Blue”, “Red”, “Yellow” }

The output is the not the intersection of the two arrays.

The solution is below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChenTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A= new string[] {"Blue","Green","Yellow","Red"};
            string[] B= new string[] {"Blue","Red","Yellow"};
            
            var result = A.Except(B).Union(B.Except(A));

            foreach (string element in result)
            {
                Console.WriteLine(element);
            }

            Console.ReadKey(false);
        }
    }
}

Read More