Created
March 20, 2013 16:40
-
-
Save frockenstein/5206170 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
// linqpad example | |
void Main() | |
{ | |
Car.Go(); | |
Honda accord = new Honda("accord"); | |
Honda.Go(); // throws an error here - ref to non-static method | |
} | |
public class Car | |
{ | |
public static void Go() | |
{ | |
"car going".Dump(); | |
} | |
} | |
public class Honda : Car | |
{ | |
public Honda(string model) | |
{ | |
this.model = model; | |
} | |
public new void Go() | |
{ | |
// this class uses shared state inside of this method | |
// but breaks because Car.Go is static | |
this.model + " going".Dump(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment