BitArray and Equals riddle
I have to following code:
BitArray arr1 = new BitArray(200);
BitArray arr2 = new BitArray(200);
arr1[2] = true;
arr2[2] = true;
if (arr1.And(arr2) == arr2)
Console.WriteLine(“good”);
else
Console.WriteLine(“bad”);
It returns “bad” for some unknown reason.
My guess is that Equals implemented a reference comparison and not bitwise comparison.
It seems like a strange behavior as BitArray is classic for bitwise operations on it.
Am I missing something?
update: I’ve refactored Microsoft orginal BitArray and named it BitArray2. You can find it here.