How to Compare two arrays in C# ?

Two arrays can be compared in C# using the Enumerable.SequenceEqual method . The Enumerable.SequenceEqual method in C# returns a boolean value indicating if both the arrays are equal or not.

How to Compare two arrays in C# ?

Below is an example of comparison of two arrays in C# using the Enumerable.SequenceEqual method.

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

namespace AbundantCodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] inputStr = { "Java", "CSharp", "Xamarin", "Windows", "android", "iOS" };
            string[] inputStr2 = { "Java", "CSharp", "Xamarin", "Windows", "android", "iOS" };
            string[] inputStr3 = { "Java", "CSharp", "Xamarin", "Windows", "android", "Windows Phone" };
            Console.WriteLine("Comparison result of inputStr and input2 is " + Enumerable.SequenceEqual(inputStr, inputStr2));
            Console.WriteLine("Comparison result of inputStr and input3 is " + Enumerable.SequenceEqual(inputStr, inputStr3));
            Console.ReadLine();
        }
    }
}
image