A simple generic class hierarchy : Generic Hiearchy « Generic « C# / CSharp Tutorial






using System; 
 
class Gen<T> {  
  T ob; 
    
  public Gen(T o) {  
    ob = o;  
  }  
  
  public T getob() {  
    return ob;  
  }  
}  
 
class Gen2<T> : Gen<T> { 
  public Gen2(T o) : base(o) { 
  } 
} 
 
class MainClass { 
  public static void Main() { 
    Gen2<string> g2 = new Gen2<string>("Hello"); 
 
    Console.WriteLine(g2.getob()); 
  } 
}
Hello








18.16.Generic Hiearchy
18.16.1.A simple generic class hierarchy
18.16.2.A derived class can add its own type parameters
18.16.3.A nongeneric class can be the base class of a generic derived class
18.16.4.Overriding a virtual method in a generic class