Ejemplo n.º 1
0
    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 SomethingThatAdds(ICanAdd adder)
 {
     _adder = adder;
 }
 public SomethingThatAdds(ICanAdd adder)
 {
     _adder = adder;
 }