8
C#中对象的内存地址
我前段时间编写了一个函数(针对.NET 3.5),现在我已升级到4.0 我无法正常工作。 该函数是: public static class MemoryAddress { public static string Get(object a) { GCHandle handle = GCHandle.Alloc(a, GCHandleType.Pinned); IntPtr pointer = GCHandle.ToIntPtr(handle); handle.Free(); return "0x" + pointer.ToString("X"); } } 现在,当我调用它时-MemoryAddress.Get(new Car(“ blue”)) public class Car { public string Color; public Car(string color) { Color = color; } } …