Skip to content

Instantly share code, notes, and snippets.

@kg
Forked from TryJSIL/Interfaces.cs
Created April 28, 2012 09:33

Revisions

  1. @TryJSIL TryJSIL created this gist Apr 27, 2012.
    34 changes: 34 additions & 0 deletions Interfaces.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    using System;

    public interface I {
    void Foo ();
    }

    public class A : I {
    public void Foo () {
    Console.WriteLine("A");
    }
    }

    public class B : A, I {
    void I.Foo () {
    Console.WriteLine("B");
    }
    }

    public static class Program {
    public static void Main (string[] args) {
    I i;

    var a = new A();
    i = a;
    a.Foo(); // expected: "A"
    i.Foo(); // expected: "A"

    var b = new B();
    i = b;
    b.Foo(); // expected: "A"
    i.Foo(); // expected: "B"

    }
    }