Linq recipe #3, flatten a dictionary of byte arrays into a single byte array

Dictionary<int, byte[]> binaryParts = new Dictionary<int, byte[]>();

// now combine the binary from all the parts by first sorting by key

var flattenedList = binaryParts.OrderBy(p => p.Key).SelectMany(p => p.Value);

byte[] combinedBytes = flattenedList.ToArray();

Leave a comment