关于How to cast while Sorting?,我尝试了以下答案之一。
vehicleList.OrderBy(c=>
{
Car car = c as Car;
if (car != null)
return car.ModelName
else
return "";
}
但这会导致编译器错误:
The type arguments for method 'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
这有什么问题?如何纠正?
我想要达到的目标如下:
最佳答案
这样可以解决错误:
var sortedVehicles = vehicleList.OrderBy<Vehicle, string>(c=>
{
...
});
关于c# - 通过匿名方法订购,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14951618/