本文介绍了根据日期对列表进行排序时,OrderBy不会更改列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个结构体和一个如下列表,我只是想根据日期对输入点进行排序.我使用了以下命令,但看不到任何排序.
I have a struct and a list as follow, I just wanted to sort the Inputpoints according to date. I have used the following commands but I can not see any sorting.
public struct Points { public Date Date; public double Quantity; } _test = new List<Points>(InputPoints); _test.OrderBy(t => t.Date);推荐答案
调用_test.OrderBy(t => t.Date)不会不会更改_test本身的内容,而是返回已排序的IOrderedEnumerable<Points>.您可以使用ToList()将其转换为List<Points>.总而言之
Calling _test.OrderBy(t => t.Date) does not change the contents of _test itself, but rather returns a sorted IOrderedEnumerable<Points>. You can turn this back into a List<Points> using ToList(). So all in all
_test = _test.OrderBy(t => t.Date).ToList();应该做你想做的事.
更多推荐
根据日期对列表进行排序时,OrderBy不会更改列表
发布评论