Skip to content

Instantly share code, notes, and snippets.

@t3knoid
Created March 11, 2022 15:48
Show Gist options
  • Save t3knoid/37f2947341bb2e37f6abedca8235ba76 to your computer and use it in GitHub Desktop.
Save t3knoid/37f2947341bb2e37f6abedca8235ba76 to your computer and use it in GitHub Desktop.
Use this comparer to sort a list of bytes,
///
/// Usage listBytes.Sort(new ByteListComparer());
///
public class ByteListComparer : IComparer<IList<byte>>
{
public int Compare(IList<byte> x, IList<byte> y)
{
int result;
for (int index = 0; index < Math.Min(x.Count, y.Count); index++)
{
result = x[index].CompareTo(y[index]);
if (result != 0) return result;
}
return x.Count.CompareTo(y.Count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment