[StructLayout(LayoutKind.Explicit)]
public struct struct1
{
[FieldOffset(0)]
public byte a; // 1 byte
[FieldOffset(1)]
public int b; // 4 bytes
[FieldOffset(5)]
public short c; // 2 bytes
[FieldOffset(7)]
public byte buffer;
[FieldOffset(18)]
public byte[] shaHashResult; // 20 bytes
}
void DoStuff()
{
struct1 myTest = new struct1();
myTest.shaHashResult = sha256.ComputeHash(pkBytes); // 20 bytes
byte[] newParameter = myTest.ToArray() //<-- How do I convert a struct
// to array without a copy?
}
如何获取数组myTest
并将其转换为字节 []?由于我的对象很大,我不想复制数组(memcopy 等)