2 using System.Runtime.InteropServices;
5 [StructLayout ( LayoutKind.Explicit )]
7 [ FieldOffset(0) ] public int a;
8 [ FieldOffset(0) ] public byte a1;
9 [ FieldOffset(1) ] public byte a2;
10 [ FieldOffset(2) ] public byte a3;
11 [ FieldOffset(3) ] public byte a4;
13 [StructLayout ( LayoutKind.Explicit )]
15 [ FieldOffset(0) ] public int a;
16 [ FieldOffset(0) ] public byte a1;
17 [ FieldOffset(1) ] public byte a2;
18 [ FieldOffset(2) ] public byte a3;
19 [ FieldOffset(3) ] public byte a4;
21 [StructLayout ( LayoutKind.Explicit )]
22 public class Doh3: Doh2 {
23 [ FieldOffset(0) ] public int b;
26 public static int Main() {
28 Doh3 doh2 = new Doh3 ();
30 // shut up the compiler
31 doh.a1 = doh.a2 = doh.a3 = doh.a4 = 0;
33 if (doh.a1 == 1 && doh.a2 == 0 && doh.a3 == 0 && doh.a4 == 0) {
34 System.Console.WriteLine ("Little endian");
36 } else if (doh.a1 == 0 && doh.a2 == 0 && doh.a3 == 0 && doh.a4 == 1) {
37 System.Console.WriteLine ("Big endian");
42 // shut up the compiler
43 doh2.a1 = doh2.a2 = doh2.a3 = doh2.a4 = 0;
45 if (doh2.a1 == 1 && doh2.a2 == 0 && doh2.a3 == 0 && doh2.a4 == 0) {
47 } else if (doh2.a1 == 0 && doh2.a2 == 0 && doh2.a3 == 0 && doh2.a4 == 1) {