473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem with byte Array compare

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[i] != keytocheck[i])
return false;
}

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

regards
Norbert

Nov 17 '05 #1
2 16320
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"nobs" <no**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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[i] != keytocheck[i])
return false;
}

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

regards
Norbert

Nov 17 '05 #2
nobs <no**********@gmail.com> wrote:
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[i] != keytocheck[i])
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: José Joye | last post by:
I have to compare 2 byte and I must be sure that they are fully identic. I have to perform this check about 1000 times per minute and on arrays that are between 100-200K in size. In that sense,...
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
5
by: Vai2000 | last post by:
Hi All, I have a ClassA and a worker ClassB. in my ClassA I have a method which calls the following routine for(int idx=0;idx<10;idx++) { ClassB ob=new ClassB(); ThreadPool.QueueUserWorkItem(new...
3
by: NathanV | last post by:
I'm trying to compare two byte's. I think I have to use binary operators. How can I tell if two bytes have the same value? Also, I have a function that is returning a byte value. Is there a...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: Angel J. Hernández M | last post by:
Hi folks! I'm having a little problem and I'm a bit confused about it. See... I'm working on this VoIP project (I need to use make direct calls to Windows API). I started working using C# but since...
2
by: Tom | last post by:
What's the best way to compare two byte arrays? Right now I am converting them to base64 strings and comparing those, as so: 'result1 and result2 are two existing byte arrays that have been...
3
by: Terry | last post by:
In the code below, I open a file using filestream, copy it to a byte array, and the write that array out to a new file. But when I check the size of the original file and the new file, the new...
4
by: eoghan.kenny | last post by:
Hi, I need to compare two timestamp columns in sql server and see which one is greater. (i can tell if they are not equal buts not enough for this requirement). A timestamp value is unique in...
5
by: Oleg Subachev | last post by:
Is there other way of comparing two byte arrays than iterating through the two and compare individual bytes ? Oleg Subachev
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.