C# Generics and polymorphism: an oxymoron?

前端 未结 6 1608
日久生厌
日久生厌 2020-12-16 12:17

I just want to confirm what I\'ve understood about Generics in C#. This has come up in a couple code bases I\'ve worked in where a generic base class is used to create type

6条回答
  •  [愿得一人]
    2020-12-16 12:51

    public Class ReflectionReport 
    {
        // This class uses Reflection to produce column-based grids for reporting.  
        // However, you need a type in order to know what the columns are. 
    }
    
    ... so, in another class you have...
    
    public Class ReflectionReportProject {
        ReflectionReport thangReport = new ReflectionReport(); 
        ReflectionReport thongReport = new ReflectionReport(); 
    
    
    
        ... some more stuff ...
    
        // Now, you want to pass off all of the reports to be processed at one time....
        public ReflectionReport[] ProvideReports() 
        {
            return new ReflectionReport[] { thangReport, thongReport } ;
        }
    }
    

提交回复
热议问题