【发布时间】:2011-07-29 08:24:46
【问题描述】:
我的代码如下
class MyClass
{
static int iField = 42;
static void Test(ref int arg)
{
unsafe
{
fixed(void* pField = &iField)
fixed(void* pArg = &arg)
{
Console.WriteLine ("{0},{1}",(int)pArg,(int)pField);
//output: 165451772,165451772
}
}
}
static void Main()
{
Test(ref iField);
}
}
我想知道获取 ref 参数的地址是否像上面测试中显示的那样可靠。
【问题讨论】:
-
顺便说一句,我还想知道结构/类的值类型静态字段是否会在其生命周期内保持其地址不变。