I have an array of all the bytes in a file.
{ 0xA0, 0x00, 0xFF, 0xFF, 0xA0, 0x10, 0x01, 0x00, 0x10, 0x32, 0x0D, 0x00, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x2C, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x21, 0x00, 0xF0, 0xF0 }
I also have a function that reads a certain section of the file, and moves the location farther forward. (Like BinaryReader.ReadX() except in an array.
private static byte[] readBytes(int length)
{
cursorLocation += length;
return new ArraySegment<byte>(bytes, cursorLocation-length, length).ToArray();
}
However, when I try to test if a certain section of bytes are the same, it seems to not work. For example, this:
byte[] startup = readBytes(4);
if (startup == new byte[] { 0xA0, 0x00, 0xFF, 0xFF })
{
Console.WriteLine("Matches");
} else
{
Console.WriteLine("Does not match.");
}
returns "Does Not Match," instead of "Matches." I have also tried comparing each array piece in a row, but that also does not work. Printing them out in a line like so:
Console.WriteLine(startup[0]);
Console.WriteLine(startup[1]);
Console.WriteLine(startup[2]);
Console.WriteLine(startup[3]);
returns, as expected:
160
0
255
255
I am really not sure what is wrong, and any help would be greatly appreciated. Thanks so much!
==on arrays is a reference equality check, not a contents check.===instead or something? Thanks