Created
June 1, 2013 14:12
-
-
Save akimboyko/5690522 to your computer and use it in GitHub Desktop.
Readonly not really readonly. From http://www.slideshare.net/SergeyTeplyakov/c-sharp-deep-dive — by @steplyakov
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
| // from http://www.slideshare.net/SergeyTeplyakov/c-sharp-deep-dive | |
| // by @STeplyakov | |
| void Main() | |
| { | |
| var s3 = new S3(); | |
| s3.S2.X = 42; | |
| s3.Dump(); | |
| } | |
| struct S1 | |
| { | |
| // this is readonly, really? :) | |
| private readonly int X; | |
| public int GetX() { return X; } | |
| } | |
| struct S2 | |
| { | |
| public int X; | |
| } | |
| [StructLayout(LayoutKind.Explicit)] | |
| struct S3 | |
| { | |
| [FieldOffset(0)] | |
| public S1 S1; | |
| [FieldOffset(0)] | |
| public S2 S2; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment