c#中如何取得一个变量在内存里面的地址!
2个回答
展开全部
添加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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询