我有返回的代码和 IVehicle 接口(interface)数组
IEnumerable<IVehicle> allVehicles = GetAllVehicles();
我知道所有这些对象都是 Car 对象。什么是正确的施法方式
IEnumerable<IVehicle>
到
IEnumerable<Car>
因为我需要将这些传递给另一个需要
<Enumerable<Car>
的函数
最佳答案
你可以像这样转换它:
var allCars = allVehicles.Cast<Car>();
关于c# - 在 C# 中,将接口(interface)列表转换为对象列表的推荐方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33920222/