473,386 Members | 1,752 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,386 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 16319
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.