C# generics problem - newing up the generic type with parameters in the constructor

前端 未结 7 742
闹比i
闹比i 2020-12-09 04:02

I am trying to create a generic class which new\'s up an instance of the generic type. As follows:

public class HomepageCarousel : List
            


        
7条回答
  •  清歌不尽
    2020-12-09 04:39

    Have you considered using Activator (this is just another option).

    T homepageMgmtCarouselItem = Activator.CreateInstance(typeof(T), pageData) as T;
    

提交回复
热议问题