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>
.
Results. IList<T> uses 40 Bytes more than List<T> .
The main difference between List and IList in C# is that List is a class that represents a list of objects which can be accessed by index while IList is an interface that represents a collection of objects which can be accessed by index.
IList<string> strings = new List<string>(); The preceeding line of code will work, but you will only have the members of IList available to you instead of the full set from whatever class you initialize.
Try
List<SubProduct> subProducts = new List<SubProduct>(Model.subproduct);
or
List<SubProduct> subProducts = Model.subproducts as List<SubProduct>;
How about this:
List<SubProduct> subProducts = Model.subproduct.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With