我正在尝试合并多个 List<T> where T:IGetTime
(即 T
将始终具有方法 getTime()
)。
然后我尝试按 DateTime
订购商品那getTime()
返回。
我的 LINQ 看起来像这样:
public static List<T> Combine(List<T> one, List<T> two, List<T> three)
{
var result = from IGetTime item in one
from IGetTime item2 in two
from IGetTime item3 in three
select new{ item, item2, item3 };
return result.ToList();
}
我还没有添加 orderby
.应该看起来像这样:
var thestream = from T item in this
orderby item.getTime() descending
select item;
有没有办法合并和排序最终列表????
提前致谢
罗伯托
最佳答案
这里有三个列表 - 您究竟想根据什么来订购?
您的转换也不正确 - 结果将是 IEnumerable<X>
其中 X
是具有三个 T
的匿名类型在.
如果这个想法真的是连接三个列表然后排序,您需要:
return one.Concat(two)
.Concat(three)
.OrderByDescending(x => x.GetTime())
.ToList();
关于c# - LINQ- 组合多个 List<T> 并按值排序 (.Net 3.5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/396621/