Well, I wanted to hash a password, and i had a look at how ASP.net Identity does in the Microsoft.AspNet.Identity.Crypto Class, and i came along this function (which is used to compare the 2 password Hashes):
[MethodImpl(MethodImplOptions.NoOptimization)]
private static bool ByteArraysEqual(byte[] a, byte[] b)
{
if (object.ReferenceEquals(a, b))
{
return true;
}
if (((a == null) || (b == null)) || (a.Length != b.Length))
{
return false;
}
bool flag = true;
for (int i = 0; i < a.Length; i++)
{
flag &= a[i] == b[i];
}
return flag;
}
This is a direct copy from the reflector output...
Now my question is, what is the NoOptimization attribute good for, and why should it be there(what would happen if i remove it)? To me, it looks like a default Equals() implementation until the for-loop.
I tried to have a look at the IL but it is all nonsense to me :/