What is the most efficient way to combine multiple variables of different Types into a single byte-array?
Take the following example data:
short a = 500;
byte b = 10;
byte[] c = new byte[4];
How could I combine these three variables into one byte array without wasting to much time and memory?
Think of it like this (Pseudocode):
var combinedArray = new byte[] { a, b, c };
I thought of different ways, including unsafe code, converting them to byte[] using BitConverter and using Linq's Concat.
I need an array in the end, not just an IEnumerable, because I need to send this data via udp.
Are there any methods I did not think of?