需要应用命名空间:
using System.Runtime.InteropServices;
获取object对象的IntPtr:
int a = 2;
GCHandle handle = GCHandle.Alloc(a);
IntPtr p = GCHandle.ToIntPtr(handle);
通过IntPtr获取object对象
int b = Marshal.PtrToStructure<int>(p);
using System.Runtime.InteropServices;
int a = 2;
GCHandle handle = GCHandle.Alloc(a);
IntPtr p = GCHandle.ToIntPtr(handle);
int b = Marshal.PtrToStructure<int>(p);