【发布时间】:2015-11-25 15:22:33
【问题描述】:
我有返回的代码和 IVehicle 接口数组
IEnumerable<IVehicle> allVehicles = GetAllVehicles();
而且我知道所有这些对象都是 Car 对象。什么是正确的投射方式
IEnumerable<IVehicle>
到
IEnumerable<Car>
因为我需要将这些传递给另一个需要<Enumerable<Car>的函数
【问题讨论】:
-
看看
OfType<Car>()和Cast<Car>()
标签: c# collections casting