IComparerable and Byte[]

  • Thread starter Thread starter wvueagle84
  • Start date Start date
W

wvueagle84

I am trying to sort a structure which has two elements with the sort
being ascending on a field of type byte[] I keep running into walls on
how to implement the ICompare to sort byte[].

Any help/suggestions would be great.
 
This is how I implemented IComparable for data set rows:

private class FilenamesComparer : IComparer<SomeIndex.FileRow>
{
public int Compare( ImageIndex.FileRow x,
ImageIndex.FileRow y )
{
return String.Compare( ( x as
ImageIndex.FileRow ).Path,
( y as
ImageIndex.FileRow ).Path );
}
}

I'm sorting files by their path here. Maybe it can help you.
 
I am trying to sort a structure which has two elements with the sort
being ascending on a field of type byte[] I keep running into walls on
how to implement the ICompare to sort byte[].

Any help/suggestions would be great.

Compare each byte array, byte by byte, and when you see a difference,
return the appropriate value (eg -1 or 1). If one of the arrays
finishes before the other, work out which way you want that to sort -
I'd suggest making the short one sort to "before" the longer one.

If the two byte arrays finish at the same point and there haven't been
any differences, return 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

AND operator with byte operands 2
IComparable Byte-Array Comparison 1
Convert to Byte 5
Sorting 19
Byte Array 4
How to I assign some bytes in hex to a byte array 6
Byte[] Conversion 15
Byte[] and File 6

Back
Top