public static void Main() { ICoffeeBar first = new CoffeeBar(); ICoffeeBar second = new FancyCoffeeBar(); first.Brew(1); second.Brew(1); }
public static void Main() { CoffeeBar first = new CoffeeBar(); FancyCoffeeBar second = new FancyCoffeeBar(); // Case #1 - Can not call extension on concrete type that does not override // coffee_do_not_work.cs(34,10): error CS1061: 'CoffeeBar' does not contain a definition for 'Brew' and no extension method 'Brew' accepting a first argument of type 'CoffeeBar' could be found (are you missing a using directive or an assembly reference?) first.Brew(1); // Case #1.1 - However, you can call it on a type that overrides ?! second.Brew(1); // Case 1.2 - You can also use this ugly cast ((ICoffeeBar)first).Brew(1); }