using System;
class MyClass
{
public unsafe void Method()
{
int x = 10;
int y = 20;
int *ptr1 = &x;
int *ptr2 = &y;
Console.WriteLine((int)ptr1);
Console.WriteLine((int)ptr2);
Console.WriteLine(*ptr1);
Console.WriteLine(*ptr2);
}
}
class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
mc.Method();
}
}
/*************************************************************/
/*************************************************************/
/*************************************************************/
/*************************************************************/
if there is a notice :"程式中若有 unsafe 程式碼,編譯時必須使用 /unsafe 選項"
solution : 在專案屬性->組態屬性->建置中 , 有一個項目是 "容許 Unsafe 程式碼區塊" , 把它設為 true, compiler 就會自己加上 /unsafe 的參數了 .

class MyClass
{
public unsafe void Method()
{
int x = 10;
int y = 20;
int *ptr1 = &x;
int *ptr2 = &y;
Console.WriteLine((int)ptr1);
Console.WriteLine((int)ptr2);
Console.WriteLine(*ptr1);
Console.WriteLine(*ptr2);
}
}
class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
mc.Method();
}
}
/*************************************************************/
/*************************************************************/
/*************************************************************/
/*************************************************************/
if there is a notice :"程式中若有 unsafe 程式碼,編譯時必須使用 /unsafe 選項"
solution : 在專案屬性->組態屬性->建置中 , 有一個項目是 "容許 Unsafe 程式碼區塊" , 把它設為 true, compiler 就會自己加上 /unsafe 的參數了 .
沒有留言:
張貼留言