Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created September 18, 2024 23:16
Show Gist options
  • Save bg1bgst333/df979e2da6be5a4587607b52fad8028f to your computer and use it in GitHub Desktop.
Save bg1bgst333/df979e2da6be5a4587607b52fad8028f to your computer and use it in GitHub Desktop.
unsafeBlock
// メインクラス
class MainClass // MainClassクラスの定義
{
// メインメソッド
static void Main() // Mainメソッドの定義
{
// int型nをi23で初期化.
int n = 123;
// nを出力.
System.Console.WriteLine("n = " + n);
// unsafeブロックの中でポインタを使う.
unsafe
{
// 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