关于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.
有什么不对呢?如何纠正?
我试图实现的是如下:
- 排序MODELNAME如果对象是类型的车
- 否则,如果这类列车的对象ID,然后通过TrainName。
你的代码说'联系',但你说的是'汽车'和'火车'!什么是'uiItems'? – 2013-02-19 07:06:31
对不起,我把实际的程序代码...我使用车辆,因为它很容易理解...现在会改正。谢谢 – user2025418 2013-02-19 07:08:02
'vehicleList'的类型是什么?通常你不应该得到这个错误。 – 2013-02-19 07:41:49