Equivalent in C# of Python's “struct.pack/unpack”?

前端 未结 3 1983
太阳男子
太阳男子 2021-01-12 05:25

I am a seasoned Python developer and have come to love a lot of its conveniences. I have actually known C# for some time but recently have gotten into some more advanced cod

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 06:16

    BinaryWriter and BinaryReader will send arbitrary items to a byte array or read arbitrary items from a byte array

    var str = new MemoryStream();
    var bw = new BinaryWriter(str);
    bw.Write(42);
    bw.Write("hello");
    ...
    var bytes = str.ToArray();
    

提交回复
热议问题