帮助,不能如何运行不安全

时间:2010-12-12 18:39:46

标签: c#-4.0

如何运行csc / unsafe * .cs

using System;

class UnsafeCode
{
      unsafe static void Main()      
      {
        int count = 99;
        int* p;
        p = &count;
        Console.WriteLine("Initial value of count is " + *p);
        *p = 10;
        Console.WriteLine("New value of count is " + *p);
      }
}

错误1只有在使用/ unsafe C编译时才会出现不安全的代码:\ Documents and Settings \ Eddy Ho \ My Documents \ Visual Studio 2010 \ Projects \ 608-UnsafeCode-Errors \ 608-UnsafeCode-Errors \ Program.cs 5 26 608-UnsafeCode

1 个答案:

答案 0 :(得分:3)

这是一个命令行参数。

使用Visual Studio命令提示符并输入。

您也可以在IDE中设置此项,方法是转到项目的属性,然后在Build标签中选择Allow unsafe code复选框。请参阅here