在C#中有一种方法可以将普通字节数组转换为对象吗?
例如,给这个班:
class Data
{
public int _int1;
public int _int2;
public short _short1;
public long _long1;
}
Run Code Online (Sandbox Code Playgroud)
我想基本上能够做这样的事情:
var bytes = new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0 };
var obj = (Data)bytes;
Run Code Online (Sandbox Code Playgroud) c# ×1