Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,930 questions

51,863 answers

573 users

How to compare two byte arrays in C#

4 Answers

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr1 = new byte[] { 1, 2, 3, 4, 5 };
            var arr2 = new byte[] { 1, 2, 3, 4, 5 };

            var b = arr1.SequenceEqual(arr2);

            Console.WriteLine(b);
        }
    }
}


/*
run:
 
True
 
*/

 



answered Apr 29, 2017 by avibootz
0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr1 = new byte[] { 1, 2, 3, 4, 5 };
            var arr2 = new byte[] { 1, 2, 3, 4, 7 };

            var b = arr1.SequenceEqual(arr2);

            Console.WriteLine(b);
        }
    }
}


/*
run:
 
False
 
*/

 



answered Apr 29, 2017 by avibootz
0 votes
using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern int memcmp(byte[] arr1, byte[] arr2, long count);

        static void Main(string[] args)
        {
            var arr1 = new byte[] { 1, 2, 3, 4, 5 };
            var arr2 = new byte[] { 1, 2, 3, 4, 5 };

            bool b = arr1.Length == arr2.Length && memcmp(arr1, arr2, arr2.Length) == 0;

            Console.WriteLine(b);
        }
    }
}


/*
run:
 
True
 
*/

 



answered Apr 29, 2017 by avibootz
0 votes
using System;
using System.Collections;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr1 = new byte[] { 1, 2, 3, 4, 5 };
            var arr2 = new byte[] { 1, 2, 3, 4, 5 };

            bool b = StructuralComparisons.StructuralEqualityComparer.Equals(arr1, arr2);

            Console.WriteLine(b);
        }
    }
}


/*
run:
 
True
 
*/

 



answered Apr 29, 2017 by avibootz

Related questions

1 answer 117 views
117 views asked Jun 5, 2023 by avibootz
1 answer 169 views
169 views asked Sep 23, 2016 by avibootz
1 answer 38 views
38 views asked Jul 12, 2025 by avibootz
2 answers 142 views
2 answers 108 views
3 answers 184 views
184 views asked Jan 25, 2022 by avibootz
...