Problem with byte Array compare

  • Thread starter Thread starter nobs
  • Start date Start date
N

nobs

Hi

I have two byte arrays (each with a length of 8 bytes)
an I'd like to compare them if they are equal.

The operator == shouldn't work because its not a basic Data Type
so I used the method Equal, but it also isn't working.

right know I use
if(mykey.Length!= keytocheck.Length)
return false;
for (int i = 0; i < mykey.Length; i++)
{
if (mykey != keytocheck)
return false;
}

This is working, but why I cannot use the Equal method??
Can somebody explain it to me?

regards
Norbert
 
Norbert,

Quite simply, the Equals method is not overridden to provide the
semantics you desire. You will have to perform this check, or wrap it in a
utility method if this is the result you desire.

Hope this helps.
 
nobs said:
I have two byte arrays (each with a length of 8 bytes)
an I'd like to compare them if they are equal.

The operator == shouldn't work because its not a basic Data Type

Well, if == had been overloaded for byte arrays, that would still work
just fine.
so I used the method Equal, but it also isn't working.

right know I use
if(mykey.Length!= keytocheck.Length)
return false;
for (int i = 0; i < mykey.Length; i++)
{
if (mykey != keytocheck)
return false;
}

This is working, but why I cannot use the Equal method??


Because Equals hasn't been overridden to compare arrays. The above
looks fine though.
 
Back
Top