You can make your code a little shorter using Array.Copy, but there is no GetBytes overload or equivalent in BitConverter that puts bytes directly into your buffer.
Maybe BinaryWriter on a MemoryStream what do you want?
Note that by accepting BitConverter APIs that you donβt like, you are causing the same problem for users of your class. Instead, write a method that takes BinaryWriter and serializes your class into it, this spreads well when your class is embedded in some other object.
source share