Skip to content

Instantly share code, notes, and snippets.

@gene9
Forked from TryJSIL/InheritGenericClass.cs
Created April 27, 2016 13:17
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 gene9/496b8e064846df247889896a2fd34872 to your computer and use it in GitHub Desktop.
Save gene9/496b8e064846df247889896a2fd34872 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