Created
September 18, 2024 23:16
-
-
Save bg1bgst333/df979e2da6be5a4587607b52fad8028f to your computer and use it in GitHub Desktop.
unsafeBlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// メインクラス | |
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