Search code examples
c#listcastingilist

Cast IList to List


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

List<SubProduct> subProducts= Model.subproduct;

Model.subproduct returns IList<SubProduct>.


Solution

  • Try

    List<SubProduct> subProducts = new List<SubProduct>(Model.subproduct);
    

    or

    List<SubProduct> subProducts = Model.subproducts as List<SubProduct>;