Last active
December 24, 2025 22:19
-
-
Save sunmeat/80087d130f4a8765afc4bfe83b7cf66f to your computer and use it in GitHub Desktop.
unsafe code example
This file contains hidden or 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
| // компілювати цей додаток потрібно з параметром /unsafe !!! | |
| // https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/language | |
| // https://www.dotnetperls.com/unsafe | |
| class UnsafelApp | |
| { | |
| public static unsafe void GetValues(int* x, int* y) | |
| { | |
| *x = 6; | |
| *y = 42; | |
| } | |
| public static unsafe void Main() | |
| { | |
| unsafe | |
| { | |
| int iData = 10; | |
| int* pData = &iData; | |
| Console.WriteLine("Data is " + iData); | |
| Console.WriteLine("Address is " + (long)pData); | |
| } | |
| int a = 1; | |
| int b = 2; | |
| Console.WriteLine("Before GetValues(): a = {0}, b = {1}", a, b); | |
| GetValues(&a, &b); | |
| Console.WriteLine("After GetValues(): a = {0}, b = {1}", a, b); | |
| } | |
| } | |
| // іще 16 прикладів коду: https://www.codeproject.com/Articles/1099/Writing-Unsafe-code-using-C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment