<p>How can I do this fast?</p>

<p>Sure I can do this:</p>

<pre><code>static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i=0; i&lt;a1.Length; i++)
        if (a1[i]!=a2[i])
            return false;

    return true;
}
</code></pre>

<p>But I'm looking for either a <a href="https://en.wikipedia.org/wiki/Standard_Libraries_%28CLI%29#Base_Class_Library" rel="noreferrer">BCL</a> function or some highly optimized proven way to do this.</p>

<pre><code>java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);
</code></pre>

<p>works nicely, but it doesn't look like that would work for x64.</p>

<p>Note my super-fast answer <a href="https://stackoverflow.com/a/8808245/4489">here</a>.</p>

I would use unsafe code and run the
```
for
```
loop comparing Int32 pointers.
Maybe you should also consider checking the arrays to be non-null.