void Main() { MyAdder myAdder = new MyAdder(); // Even though ICanAdd is not implemented by MyAdder, // we can duck cast it because it implements all the members: ICanAdd adder = DuckTyping.Cast <ICanAdd>(myAdder); // Now we can call adder as you would any ICanAdd object. // Transparently, this call is being forwarded to myAdder. int sum = adder.Add(2, 2); }
public int AddNumbers() { return(_adder.Add(FirstNumber, SecondNumber)); }