首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么能获得变量的内存地址

2012-08-28 
如何能获得变量的内存地址?C# codeStringBuilder dict new StringBuilder()声明了一个变量 dict , 如何

如何能获得变量的内存地址?

C# code
StringBuilder dict = new StringBuilder();


声明了一个变量 dict , 如何知道 dict 的内存地址?

[解决办法]
http://msdn.microsoft.com/zh-cn/library/zcbcf4ta.aspx
[解决办法]
class AddressOfOperator
{
staticvoid Main()
{
int number;

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);
}

// Print the value of the variable number:
System.Console.WriteLine("Value of the variable number: {0:X}", number);

System.Console.ReadKey();
}
}

热点排行