Created
September 17, 2024 23:41
-
-
Save bg1bgst333/069c7ee3479d9afffd62850fd9f27458 to your computer and use it in GitHub Desktop.
unsafeMethod
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メソッドの定義 | |
{ | |
// 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