// 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; namespace E { public interface ISomething { void Tell(); } public class SomethingA : ISomething { public void Tell() { Console.WriteLine("I am an A"); } } public class SomethingB : ISomething { public void Tell() { Console.WriteLine("I am a B"); } } public class Program { // Test does only know about the interface public static void Test(ISomething o) { o.Tell(); } public static void Main(string[] args) { SomethingA a = new SomethingA(); // here we could call SomethingA specific members Test(a); SomethingB b = new SomethingB(); // here we could call SomethingA specific members Test(b); } } }