IList to IList

后端 未结 8 1092
猫巷女王i
猫巷女王i 2021-01-05 00:28

I have a few classes:

class Vehicle
{
}

class Car : Vehicle
{
}

I have a list of the derived class: IList cars;

8条回答
  •  误落风尘
    2021-01-05 00:58

    Use IEnumerable.Cast :

    IList vehicles = cars.Cast().ToList();
    

    Alternatively, you may be able to avoid the conversion to List depending on how you wish to process the source car list.

提交回复
热议问题