0

I have a byte array and a byte list, they both contains same numbers. how should I compare them.

code i am using, but not working:

if (portBuffer.Equals(ret_bytes))
         status = 0;

The following image is captured when i was debugging. they basicly contains same bytes. I know they are belonging to different object, but how to cast them? thanks

a busy cat http://img29.imageshack.us/img29/5769/33818425.jpg !

1
  • 4
    See how far you get with SequenceEquals Commented Feb 21, 2012 at 4:10

2 Answers 2

3

use the extension method SequenceEqual.

using System.Linq;

//...

if (portBuffer.SequenceEqual(ret_bytes))
         status = 0;
Sign up to request clarification or add additional context in comments.

2 Comments

Do you mind explain just a little what is linq? what does it do?
Think about linq as a component that allows you to query objects collections, xml, databases etc...In practice, the namespace System.Linq adds a lot of extension methods to allow the querying. So, when you add that using clause, you are making the method SequenceEqual available to all collections that implement IEnumerable.
2

If you want to use linq, try:

var arraysAreEqual = Enumerable.SequenceEqual(portBuffer, ret_bytes); 

I am not at my pc so I cannot tell you if any casting is needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.