Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created September 17, 2024 23:41
Show Gist options
  • Save bg1bgst333/069c7ee3479d9afffd62850fd9f27458 to your computer and use it in GitHub Desktop.
Save bg1bgst333/069c7ee3479d9afffd62850fd9f27458 to your computer and use it in GitHub Desktop.
unsafeMethod
// メインクラス
class MainClass // MainClassクラスの定義
{
// メインメソッド
static void Main() // Mainメソッドの定義
{
// UnsafeMethodを呼ぶ.
UnsafeMethod();
}
// アンセーフメソッド
unsafe static void UnsafeMethod()
{
// int型nをi23で初期化.
int n = 123;
// nを出力.
System.Console.WriteLine("n = " + n);
// int型ポインタpをnのアドレスで初期化.
int* p = &n;
// pの参照先に456を代入.
*p = 456;
// nを出力.
System.Console.WriteLine("n = " + n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment