struct aa { public string a; public string b; } aa p = new aa(); p.a = "1"; p.b = "1"; //对象转IntPtr var handle = GCHandle.Alloc(p); var ptr = GCHandle.ToIntPtr(handle); //IntPtr转对象 var a = GCHandle.FromIntPtr(ptr) .Target; handle.Free();
2021-09-25 20:27:24
struct aa { public string a; public string b; } aa p = new aa(); p.a = "1"; p.b = "1"; //对象转IntPtr var handle = GCHandle.Alloc(p); var ptr = GCHandle.ToIntPtr(handle); //IntPtr转对象 var a = GCHandle.FromIntPtr(ptr) .Target; handle.Free();