【发布时间】:2013-02-26 20:43:26
【问题描述】:
根据 MSDN,我们可以在不安全的上下文中获取变量的地址。
我们可以在不安全声明的方法中获取变量的地址,但为什么不能在所有不安全的上下文中获取它?
static void Main(string[] args) {
//Managed code here
unsafe {
string str = "d";
fixed (char* t = &str[0]) {// ERROR : Cannot take the address of the given expression
}
}
//Managed code here
}
【问题讨论】:
-
什么是
g?它是如何失败的? -
您看到的错误/行为是什么?
-
对不起,我会更新问题
-
请指明是哪一行报错。
-
@evanmcdonnal 错误出现在固定线路上。
标签: c#