I have a List<byte[]>. Each byte array is of size 16bytes. The first 8 bytes is a binary representation of the C# long data type which I use to stop DateTimeTicks. I wonder whether there is a way to sort a bunch of byte arrays in the same order as if I sorted by the long equivalents in ascending order. Obviously its easy if each byte array is deserialized into a long and then sorted but is there a way to get away without deserialization? If not would it be possible to find a logic to convert a DateTimeTick value into a binary representation so that sorting can be performed directly on the binary by, for example by first expressing year in binary form, then month, day, hour, minute, second, millisecond,..? My goal is to skip the deserialization step because I need to send the sorted byte array over a messaging network in binary format and it currently wastes a lot of resources to have to first deserialize for sorting purpose (sorting has to be done before sending the object over the wire), then serialize it again to send it through the messaging system, then deserialize it again.
Any ideas, hints or solutions highly welcome, thank you.
Edit: I currently use the Linq OrderBy function to sort which is fast enough for my purpose and look something along those lines, performance wise. I would like to stick to Linq unless it is not possible to order by byte array, even if I provided an IComparer…
1 Answer