PC Review


Reply
Thread Tools Rate Thread

How to compare two byte arrays?

 
 
Ole
Guest
Posts: n/a
 
      23rd Jun 2006
How do I compare two byte arrays in a if statement?

Thanks
Ole


 
Reply With Quote
 
 
 
 
Vadym Stetsyak
Guest
Posts: n/a
 
      23rd Jun 2006
Hello, Ole!

O> How do I compare two byte arrays in a if statement?

You have to loop through array comparing every item.

Smth like

bool IsEqual(byte[] arr1, byte[] arr2)
{
if ( arr1 == null || arr2 == null )
return false;

if ( arr1.Length != arr2.Length )
return false;

//and here is the check loop
for(int i = 0; i < arr1.Length; i++ )
{
if ( arr1[i] != arr2[i] )
return false;
}
return true;
}

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Reply With Quote
 
Ole
Guest
Posts: n/a
 
      23rd Jun 2006
Hello Vadym,

Thanks alot!

Regards
Ole

"Vadym Stetsyak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello, Ole!
>
> O> How do I compare two byte arrays in a if statement?
>
> You have to loop through array comparing every item.
>
> Smth like
>
> bool IsEqual(byte[] arr1, byte[] arr2)
> {
> if ( arr1 == null || arr2 == null )
> return false;
>
> if ( arr1.Length != arr2.Length )
> return false;
>
> //and here is the check loop
> for(int i = 0; i < arr1.Length; i++ )
> {
> if ( arr1[i] != arr2[i] )
> return false;
> }
> return true;
> }
>
> --
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Performance File Compare: MD5/SHA1 or Byte-by-Byte Checking? Mahmoud Al-Qudsi Microsoft C# .NET 6 4th Apr 2007 04:48 PM
How to compare two byte arrays ? Oleg Subachev Microsoft C# .NET 5 19th Apr 2006 02:13 PM
Re: HELP! compare two SQL timestamps in C# byte arrays - My Solution Next Microsoft C# .NET 5 20th Sep 2004 06:48 PM
HELP! compare two SQL timestamps in C# byte arrays Next Microsoft ADO .NET 9 20th Sep 2004 06:48 PM
Best way to compare two BYTE arrays? Tom Microsoft VB .NET 2 12th Aug 2004 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.