我写了一个指针程序,编译的时候出错,提示:不安全的代码只会在使用/unsafe编译的情况下出现。
怎么把编译设置成/unsafe啊?
程序如下
using System;namespace 指针
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
public unsafe void Copy(int[] sor,int[] dir)
{
fixed(int *psor = sor,pdir = dir)
{
for(int i=0;i<sor.Length;i++)
{
*pdir++ = *psor++;
}
}
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
int[] a = new int[5]{1,2,3,4,5};
int[] b = new int[5];
Copy(a,b);
foreach(int i in a)
{
Console.Write("a={0} ",i);
}
foreach(int i in b)
{
Console.Write("b={0} ",i);
}
Console.Read();
}
}
}