Skip to content

Instantly share code, notes, and snippets.

@brandonbloom
Last active April 19, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonbloom/4b8c3e7698959f2bf6bc9c75a9de4b01 to your computer and use it in GitHub Desktop.
Save brandonbloom/4b8c3e7698959f2bf6bc9c75a9de4b01 to your computer and use it in GitHub Desktop.
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