Last active
September 25, 2020 07:03
-
-
Save alexzzzz/c4299ca63aa2b19e9d1152a7fa04ee21 to your computer and use it in GitHub Desktop.
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
| using System; | |
| using System.Runtime.InteropServices; | |
| class Program | |
| { | |
| [StructLayout(LayoutKind.Explicit)] | |
| struct Union | |
| { | |
| [FieldOffset(0)] | |
| public string str; | |
| [FieldOffset(0)] | |
| public FakeString fakeStr; | |
| } | |
| class FakeString | |
| { | |
| public int length; | |
| } | |
| static void Main() | |
| { | |
| var union = default(Union); | |
| union.str = "Hello, World!"; | |
| union.fakeStr.length = -42; | |
| Console.WriteLine("Hello, World!".Length); // -42 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment