// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; public class P { public void M() { Console.WriteLine("M here"); } } public class C : P { } public interface IFoobar where T : P { void CallM(T o); } public class Foobar : IFoobar where T : P { public void CallM(T o) { o.M(); } } public class Program { public static void Main(String[] args) { IFoobar fb = new Foobar

(); // compile error IFoobar fb = (IFoobar)new Foobar

(); // runtime error fb.CallM(new C()); } }