Casting of Generic List to a Class derived from a List

前端 未结 5 2042
萌比男神i
萌比男神i 2020-12-11 17:33

I created a class derived from List. However when I tried casting the class to another List object I get a runtime error. My code is similar to the one posted below:

5条回答
  •  一生所求
    2020-12-11 17:54

    try this

    public class CategoryObjCollection:List
    {
       public CategoryObjCollection(IEnumerable items) : base(items){}
    }
    
    
    cat = new CategoryObjCollection(qry);
    

提交回复
热议问题