c# - 指向全局变量的指针
问题描述
所以,我有这样的代码(详细):
namespace itssafe
{
public unsafe partial class testing : Form
{
unsafe private static int original = 10;
unsafe private int tmp;
unsafe setter() // I'll use this several time
{
tmp = original;
}
unsafe private void Form1_Load(object sender, EventArgs e)
{
setter();
}
unsafe private void timers_Tick(object sender, EventArgs e)
{
int* counter; // working
counter = &tmp; // not working, but I need this
}
}
}
我有一个名为“tmp”的全局变量,我需要创建一个指向它的指针。但我不能,因为我得到“ CS0212 You can only take the address of an unfixed expression inside of a fixed statement initializer ”错误。但是这个变量是全局的,所以我不能用这个方法创建,因为我也需要在其他地方使用。我能做些什么?
我知道我已经习惯了许多不必要的“不安全”,但我很绝望。
解决方案
推荐阅读
- angular - http-server -p 8082 显示 ERR_INVALID_REDIRECT
- xamarin.forms - xamarin shell:动态生成路由页面
- python - 在 Python 中加载 AutoCAD DWG 文件
- c# - 如何解决 ARKitSample 项目的子节点快照问题?
- java - 当文件位于java项目中时,如何在Java中读取excel文件?
- python-3.x - 替换数据框中一列的值
- terraform - Terraform Apply 与 Terraform Plan 有不同的“计划”
- java - 无法在 android pie 中使用 INTENT_VIEW 它什么也没显示
- c++ - 如何在运行时切换 C++11 中的模板?
- java - 如何检查重复值转到数据库