Are 2D Arrays Equal - CSharp System

CSharp examples for System:Array Equal

Description

Are 2D Arrays Equal

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;// ww w  .j a v  a 2 s  .  c o  m

public class Main{
        public static bool Are2DArraysEqual(int[,] a1, int[,] a2)
        {
            if (a1.GetLength(0) != a2.GetLength(0)) return false;
            if (a1.GetLength(1) != a2.GetLength(1)) return false;

            for (int i = 0; i < a1.GetLength(0); i++)
            {
                for (int j = 0; j < a1.GetLength(1); j++)
                {
                    if (a1[i, j] != a2[i, j]) return false;
                }
            }

            return true;
        }
}

Related Tutorials