I read a an array of bytes from a file
I pass this to a class that then assigns various bytes from that array to various members of varying sizes.
Ideally i would like to do something like this
memberThatIsAUShort = bitconverter.ToUShort(tempArray.subArray(3,5))
memberThatIsAShort = bitconverter.ToShort(tempArray.subArray(6,8))
Instead of looping through the array, copying the bytes to new shorter array and passing them in.
You would do this as:
These methods are both static (hence
BitConvertercasing), and already provide a startIndex parameter. Since BitConverter already knows the appropriate number of bytes for a short/ushort, you don’t need to specify end indices. For details, see BitConverter.ToUInt16 and BitConverter.ToInt16.