How to check if two arrays have the same set of digits using Linq in C#

1 Answer

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        int[] arr1 = { 1, 3, 8, 5, 9, 2, 7 };
        int[] arr2 = { 2, 9, 1, 8, 2, 5, 7 };

        bool equals = arr1.OrderBy(a => a).SequenceEqual(arr2.OrderBy(a => a));

        if (equals)
              Console.WriteLine("Yes");
        else
             Console.WriteLine("No");
    }
}



/*
run:

No

*/

 



answered Dec 4, 2020 by avibootz

Related questions

...