为啥c#不能用指针啊?
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _9
{
class Program
{
unsafe static void Main(string[] args)
{
int j = 100;
int k = 100;
Console.WriteLine("Address of j={0} and address of k={1}", (int)&j, (int)&k);
Console.WriteLine("j={1},k{2}", j, k);
int* p;
p = &j;
Console.WriteLine("p now points to {1}", (int)p);
p = &k;
Console.WriteLine("p now points to {10}", (int)p);
*p = 200;
Console.WriteLine("j={1},k{2}", j, k);
Console.WriteLine("p now points to {1}", (int)p);
p = &k;
Console.WriteLine("p now points to {1}", (int)p);
*p = 300;
Console.WriteLine("j={1},k{2}", j, k);
Console.WriteLine("p now points to {1}", (int)p);
p = &k;
Console.WriteLine("j={1},k{2}", j, k);
Console.WriteLine("p now points to {1}", (int)p);
Console.ReadKey();
}
}
}
这个是拷贝的老师的课件中的程序,老师说c#中不推荐用指针,只能在非安全环境中使用,但是为啥按他自己的说法在前面加了unsafe还是编译出错?