A nongeneric class can be the base class of a generic derived class : Generic Hiearchy : Generic C# Examples


C# Examples » Generic » Generic Hiearchy »

 

A nongeneric class can be the base class of a generic derived class









    
using  System;  
  
class  NonGen  {  
    int  num;  
  
    public  NonGen(int  i)  {  
        num  =  i;  
    }  
  
    public  int  getnum()  {  
        return  num;  
    }  
}  
  
class  Gen<T>  :  NonGen  {    
    T  ob;  
        
    public  Gen(T  o,  int  i)  :  base  (i)  {    
        ob  =  o;    
    }    
    
    public  T  getob()  {    
        return  ob;    
    }    
}    
    
class  MainClass  {    
    public  static  void  Main()  {    
        Gen<String>  w  =  new  Gen<String>("Hello",  4);  
        
        Console.Write(w.getob()  +  "  ");  
        Console.WriteLine(w.getnum());  
    }    
}
    
   
  
   



Output

Hello 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Generic
» Generic Hiearchy