I have introduced the notion of blocks into my system. Each block can be split into sub-blocks.
I thought of a few ways to create or keep track of the sub-blocks within a block and one option could be to have this (any better suggestion is welcome):
// // Dictionary <sub-block-number, payload>
Dictionary <UInt16, List<byte>> _payloads { get; set; } = new Dictionary<UInt16, List<byte>>();
Now I have no problem adding things to the dictionary, but retrieving the combined payload into a byte[] is causing me problem. I have also seen a bunch of things on stack overflow (see here) using Linq, but I am not sure it is the right way to go as some people say it is very inefficient. In all cases, none of these answers return a byte[].
Here is what I would like to implement:
// Get combined payload from _payloads dictionary
public byte[] GetTotalPayload()
{ .. }
EDIT
The Lists in the dictionary will be added incrementally one by one from "sub-block-number" = 0 to N. Not sure if when combining to List it is important to specify that the key has to be ordered incrementally? Probably not.