我有一个结构:
struct S {
public readonly int Value1;
public readonly int Value2;
public S(int value1, int value2) {
this.Value1 = value1;
this.Value2 = value2;
}
}
我尝试获取 Value2 的地址:
var s = default(S);
unsafe {
var r = new IntPtr(&s.Value2);
}
但我得到一个编译器错误:
Cannot take the address of the given expression
我以为我可以获取字段的地址?这是怎么回事?