View difference between Paste ID: aqXBvEq5 and tr58wEqE
SHOW: | | - or go back to the newest paste.
1-
[StructLayout(LayoutKind.Explicit)]
1+
using System;
2-
    public struct AssemblyCache
2+
using System.Reflection;
3
using System.Runtime.InteropServices;
4
5-
        public object AssemblyLock;
5+
namespace ConsoleApplication1
6
{
7
    [StructLayout(LayoutKind.Explicit)]
8-
        public Assembly Assembly;
8+
    public struct CatOrDog
9
    {
10
        [FieldOffset(0)]
11
        public Cat Cat;
12
13
        [FieldOffset(0)]
14
        public Dog Dog;
15
    }
16-
            var cache = new AssemblyCache { AssemblyLock = new object() };
16+
17-
            Console.WriteLine(cache.Assembly != null);
17+
18
    class Program
19
    {
20
        static void Main(string[] args)
21-
    }
21+
22
            var catOrDog = new CatOrDog { Cat = new Cat { Name = "Jenny" } };
23
            catOrDog.Dog.Say();
24
        }
25
    }
26
27
    public class Cat
28
    {
29
        public string Name { get; set; }
30
31
        public void Say()
32
        {
33
            Console.WriteLine("Meow " + Name);
34
        }
35
    }
36
37
    public class Dog
38
    {
39
        public string Name { get; set; }
40
41
        public void Say()
42
        {
43
            Console.WriteLine("Woof" + Name);
44
        }
45
    }
46
}