怎么输出一个变量的内存地址

2024-12-27 03:33:31
推荐回答(1个)
回答1:

代码:
using System.Runtime.InteropServices;
using System;
namespace ConsolePrototype
{
public class A
{
}
class Program
{
static void Main(string[] args)
{
A a = new A();
GCHandle hander = GCHandle.Alloc(a);
var pin = GCHandle.ToIntPtr(hander);
Console.WriteLine(pin);
}
}
}