- // unsafe的使用
- //unsafe可以用来修饰类、类的成员函数、类的全局变量,但不能用来修饰类成员函数内的局部变量。编译带有unsafe代码的程序也要在“configuration properties>build” 中把允许unsafe代码设为真。
- public Test{
- public unsafe void add(int *p)
- {
- *p=*p+4;
- }
- public static void Main(){
- unsafe
- {
- int a = 2;
- int* p = &a;
- Test obj=new Test();
- obj.add(p);
- Console.WriteLine(*p);//6
- }
- }
- }
unsafe的使用
最新推荐文章于 2023-05-23 14:45:18 发布