A derived class with its own type parameters : Generic Class Hierarchy « Generics « C# / C Sharp






A derived class with its own type parameters

A derived class with its own type parameters

using System;

class MyClass<T> {
  T ob;

  public MyClass(T o) {
    ob = o;
  }

  public T getob() {
    return ob;
  }
}

class ClassA<T, V> : MyClass<T> {
  V ob2;

  public ClassA(T o, V o2) : base(o) {
    ob2 = o2;
  }

  public V getob2() {
    return ob2;
  }
}

class Test {
  public static void Main() {
    ClassA<string, int> x = new ClassA<string, int>("Value is: ", 9);

    Console.Write(x.getob());
    Console.WriteLine(x.getob2());
  }
}
           
       








Related examples in the same category

1.A simple generic class hierarchyA simple generic class hierarchy
2.A non-generic class can be the base class of a generic derived classA non-generic class can be the base class of a generic derived class
3.Overriding a virtual method in a generic classOverriding a virtual method in a generic class
4.The overriding method cannot change the inherited constraints.