Last active
April 19, 2018 22:29
-
-
Save brandonbloom/4b8c3e7698959f2bf6bc9c75a9de4b01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Base | |
{ | |
public virtual string Method() | |
{ | |
return "base method"; | |
} | |
} | |
class Derived : Base | |
{ | |
public override string Method() | |
{ | |
return "derived method"; | |
} | |
} | |
static class Extensions | |
{ | |
public static string Extension(this Base x) | |
{ | |
return "base extension"; | |
} | |
public static string Extension(this Derived x) | |
{ | |
return "derived extension"; | |
} | |
} | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Base a = new Base(); | |
Base b = new Derived(); | |
Console.WriteLine(a.Method()); // prints "base method" | |
Console.WriteLine(b.Method()); // prints "derived method" | |
Console.WriteLine(a.Extension()); // prints "base extension" | |
Console.WriteLine(b.Extension()); // prints "base extension" (not "derived extension!!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment