Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Created June 1, 2013 14:12
Show Gist options
  • Select an option

  • Save akimboyko/5690522 to your computer and use it in GitHub Desktop.

Select an option

Save akimboyko/5690522 to your computer and use it in GitHub Desktop.
// 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