from:http://bingya.javaeye.com/blog/657978

要在vs.net中使用unsafe code 我们必须在项目的属性中设置一下,设置方法如下:

点项目属性(Properties)->生成(Build)->常规(General)中:钩上允许不安全代码(Allow unsafe code)

 

 

C#代码 在项目中使用不安全代码【转】
  1. public static void Main(string[] args)  
  2. {  
  3.     int i = 99, y = 200;  
  4.     unsafe  
  5.     {  
  6.         swap(&i, &y);  
  7.     }  
  8.     Console.WriteLine("x is now {0},y is now {1}",i,y);  
  9. }  
  10.   
  11. public static unsafe void swap(int *a, int *b)  
  12. {  
  13.     int temp;  
  14.     temp = *a;  
  15.     *a = *b;  
  16.     *b = temp;  
  17. }  

 

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2021-06-24
  • 2021-09-05
  • 2022-12-23
  • 2021-06-05
  • 2021-11-06
  • 2022-02-13
猜你喜欢
  • 2021-08-23
  • 2022-01-08
  • 2021-11-28
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案