how to convert a value type to byte[] in C#?

前端 未结 5 1943
南旧
南旧 2020-12-11 16:36

I want to do the equivalent of this:

byte[] byteArray;
enum commands : byte {one, two};
commands content = one;
byteArray = (byte*)&content;
5条回答
  •  孤街浪徒
    2020-12-11 17:05

    You can also just do a simple cast and pass it into the array constructor. It also similar in length to the BitConverter method.

    new[] { (byte)mode }
    

提交回复
热议问题