111,092
社区成员




Node* p = new Node();
public class Node
{
public string Value { get; set; }
public Node Next;
}
public static unsafe byte[] GetBytes<T>(object obj)
{
byte[] arr = new byte[Marshal.SizeOf(obj)];
GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
void* pVer = handle.AddrOfPinnedObject().ToPointer();
fixed (byte* parr = arr)
{
*parr = *(byte*)pVer;
}
handle.Free();
return arr;
}
public static unsafe T GetObject<T>(byte[] bytes) where T : new()
{
T rect = new T();
GCHandle handle = GCHandle.Alloc(rect, GCHandleType.Pinned);
void* pVer = handle.AddrOfPinnedObject().ToPointer();
fixed (byte* b = bytes)
{
*(byte*)pVer = *b;
}
handle.Free();
return rect;
}