[英]Why do I get the error “Unsafe code may only appear if compiling with /unsafe”?
为什么我会收到以下错误?
只有在使用/ unsafe进行编译时才会出现不安全的代码?
我在C#和Visual Studio 2008中工作,在Windows CE上进行编程。
要使用不安全的代码块,必须在打开/ unsafe开关的情况下编译项目。
打开项目的属性,转到“ Build
选项卡,然后选中“ Allow unsafe code
复选框。
这是一个截图:
可能是因为你使用的是不安全的代码。
你在某处用指针或非托管程序集做某事吗?
在代码中搜索unsafe
块或语句。 这些仅对/unsafe
编译有效。
要使用不安全的代码块,请打开项目的属性,转到Build选项卡并选中Allow unsafe code复选框,然后编译并运行。
class myclass
{
public static void Main(string[] args)
{
unsafe
{
int iData = 10;
int* pData = &iData;
Console.WriteLine("Data is " + iData);
Console.WriteLine("Address is " + (int)pData);
}
}
}
输出:
Data is 10
Address is 1831848
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.