I feel silly asking but…
Using C#/.NET I have a stream and I wrote my own extension function to read short (or byte was built in).
Is there something i can use which will create an array of X length (16 in my example) and return a byte array of that? Throw an exception otherwise? ReadByte does that and is built in. There should be something like what i am asking already in the .NET framework
For byte data, you can just call Stream.Read:
Or, you could use BinaryReader.ReadBytes:
If you want to handle short data, I’d make an extension method that did this for BinaryReader: