Cast IList to List

后端 未结 9 1684
时光取名叫无心
时光取名叫无心 2020-12-08 06:09

I am trying to cast IList type to List type but I am getting error every time.

List subProducts= Model.subproduct         


        
9条回答
  •  执念已碎
    2020-12-08 06:52

    If you have an IList containing interfaces, you can cast it like this:

    List to IList

    List Foos = new List(); 
    IList IFoos = Foos.ToList();
    

    IList to List

    IList IFoos = new List();
    List Foos = new List(IFoos.Select(x => (Foo)x));
    

    This assumes Foo has IFoo interfaced.

提交回复
热议问题