Comparing two byte arrays in .NET

How can I do this fast? Sure I can do this: static bool ByteArrayCompare(byte[] a1, byte[] a2) { if (a1.Length != a2.Length) return false; for (int i=0; i<a1.Length; i++) if (a1[i]!=a2[i]) return false; return true; } But I’m looking for either a BCL function or some highly optimized proven way to do this. java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2); … Read more