Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created September 10, 2012 18:56
Show Gist options
  • Save davybrion/3692965 to your computer and use it in GitHub Desktop.
Save davybrion/3692965 to your computer and use it in GitHub Desktop.
code snippets for "Is There A Good Reason To Hide Inherited Members?" post
public class MyClass
{
public void DoSomething()
{
Console.WriteLine("i'm doing something important");
}
}
public class MyDerivedClass : MyClass
{
public void DoSomething()
{
base.DoSomething();
Console.WriteLine("(i'm just better at it)");
}
}
new public void DoSomething()
{
base.DoSomething();
Console.WriteLine("(i'm just better at it)");
}
new MyClass().DoSomething();
new MyDerivedClass().DoSomething();
static void DoIt(MyClass subject)
{
subject.DoSomething();
}
static void Main(string[] args)
{
DoIt(new MyClass());
DoIt(new MyDerivedClass());
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment