How to compare two arrays of numbers and return elements that appear only in the first array in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] numbers1 = { 2, 2, 3, 4, 5, 6 };
            int[] numbers2 = { 2, 3, 3, 7, 8, 9, 10, 11};

            IEnumerable<int> onlyInNumbers1 = numbers1.Except(numbers2);

            foreach (int n in onlyInNumbers1)
                Console.WriteLine(n);
        }
    }
}

/*
run:
    
4
5
6
       
*/

 



answered Apr 23, 2017 by avibootz

Related questions

...