// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Reflection; class MainClass { public static void Main(string[] args) { A a = new A(); B b = new B(); Display(a); Display(b); } public static void Display(object o) { Console.WriteLine("This is a " + o.GetType().Name); switch(o.GetType().Name) { case "A": Console.WriteLine("var1 = " + ((A)o).var1); break; case "B": Console.WriteLine("var2 = " + ((B)o).var2); break; } } } class A { public int var1 = 10; } class B { public int var2 = 100; }