-
-
Save gene9/496b8e064846df247889896a2fd34872 to your computer and use it in GitHub Desktop.
Generic Inheritance
This file contains 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; | |
public class GenericClass<T> { | |
public virtual void Method (T value) { | |
Console.WriteLine("GenericClass<{0}>.Method({1})", typeof(T), value); | |
} | |
} | |
public class MyClass<T> : GenericClass<T> { | |
public override void Method (T value) { | |
Console.WriteLine("MyClass.Method<{0}>({1})", typeof(T), value); | |
base.Method(value); | |
} | |
} | |
public static class Program { | |
public static void Main (string[] args) { | |
var a = (new MyClass<int>()); | |
var b = (new MyClass<string>()); | |
a.Method(1); | |
b.Method("a"); | |
a.Method(1); | |
b.Method("a"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment