static void TestInterfaceWidgets() { var w1 = new Widget(); w1.Print(); var aw = new AdvWidget(); aw.Print(); var sw = new SuperWidget(); sw.Print(); var widgets = new List <IPrintable>(); //IPrintable has one method called Print widgets.Add(w1); widgets.Add(aw); widgets.Add(sw); //inside the foreach loop, all it knows is Print foreach (var widget in widgets) { widget.Print(); } }
static void TestInterfaceWidgets() { var w1 = new Widget(); var aw = new AdvWidget(); var sw = new SuperWidget(); var widgets = new List <IPrintable>(); widgets.Add(w1); widgets.Add(aw); widgets.Add(sw); foreach (var widget in widgets) { widget.Print(); } }