You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
TrustPilotChallenge/WhiteRabbit/ByteArrayEqualityComparer.cs

39 lines
859 B

namespace WhiteRabbit
{
using System.Collections.Generic;
using System.Linq;
internal class ByteArrayEqualityComparer : IEqualityComparer<byte[]>
{
public bool Equals(byte[] x, byte[] y)
{
if (object.ReferenceEquals(x, y))
{
return true;
}
if (x?.Length != y?.Length)
{
return false;
}
return Enumerable.Range(0, x.Length).All(i => x[i] == y[i]);
}
public int GetHashCode(byte[] obj)
{
if (obj == null)
{
return 0;
}
int result = 0;
for (var i = 0; i < obj.Length; i++)
{
result = unchecked(result + (i * obj[i]));
}
return result;
}
}
}