This is a simple one, and one that I thought would have been answered. I did try to find an answer on here, but didn’t come up with anything – so apologies if there is something I have missed.
Anyway, is there an equivalent of StringBuilder but for byte arrays?
I’m not bothered about all the different overloads of Append() – but I’d like to see Append(byte) and Append(byte[]).
Is there anything around or is it roll-your-own time?
Would
MemoryStreamwork for you? The interface might not be quite as convenient, but it offers a simple way to append bytes, and when you are done you can get the contents as abyte[]by callingToArray().A more
StringBuilder-like interface could probably be achieved by making an extension method.Update
Extension methods could look like this:
Usage: