Skip to content

Instantly share code, notes, and snippets.

@TryJSIL
Created April 27, 2012 12:57
Show Gist options
  • Save TryJSIL/2508980 to your computer and use it in GitHub Desktop.
Save TryJSIL/2508980 to your computer and use it in GitHub Desktop.
Generic Inheritance
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