I am trying to compare two .NET arrays. Here is an obvious implementation for comparing arrays of bytes:
bool AreEqual(byte[] a, byte[] b){
if(a.Length != b.Length)
return false;
for(int i = 0; i < a.Length; i++)
if(a[i] != b[i])
return false;
return true;
}
A more refined approach can be seen here (via Google).
You could use SequenceEqual:
string[] a = { "1", "2", "3" };
string[] b = { "1", "2", "3" };
bool areEqual = a.SequenceEqual(b); // true
string[] c = { "1", "2", "5" };
areEqual = a.SequenceEqual(c); // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With