c#中如何取得一个变量在内存里面的地址!

2024-12-01 07:39:26
推荐回答(2个)
回答1:

添加Unsafe, 代码:
unsafe
{
// Assign the address of number to a pointer:int* p = &number;

// Commenting the following statement will remove the// initialization of number.
*p = 0xffff;

// Print the value of *p:
System.Console.WriteLine("Value at the location pointed to by p: {0:X}", *p);

// Print the address stored in p:
System.Console.WriteLine("The address stored in p: {0}", (int)p);
}
是MSDN的例子
参考 http://msdn.microsoft.com/zh-cn/library/zcbcf4ta.aspx

回答2:

套套!