Compares two arrays - CSharp System

CSharp examples for System:Array Compare

Description

Compares two arrays

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*from w ww . j  a v a  2 s .  c  o m*/

public class Main{
        /// <summary>
        /// Compares two arrays
        /// </summary>
        /// <param name="a">The Array</param>
        /// <param name="b">The Array</param>
        /// <param name="count">The count.</param>
        /// <returns></returns>
        public static bool ArrayEqual(byte[] a, byte[] b, int count)
        {
            for (int i = 0; i < count; i++)
            {
                if (a[i] != b[i])
                {
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// Compares two arrays
        /// </summary>
        /// <param name="bytes">The Array</param>
        /// <param name="data">The Array</param>
        /// <returns></returns>
        public static bool ArrayEqual(byte[] bytes, byte[] data)
        {
            if (bytes.Length == data.Length)
            {
                return ArrayEqual(bytes, data, bytes.Length);
            }
            else
            {
                return false;
            }
        }
}

Related Tutorials