使用Linq对List[]排序
本文关键字:排序 Linq List 使用 | 更新日期: 2023-09-27 18:04:26
如何排序列表
i has list list [] deliverystatus = new list [3];
deliverystatus[0]---> stores name of file
deliverystatus[1]---> file delivery date
deliverystatus[2]---> where to delivery
i将list转换为table,并通过邮件发送。我不能更改其他代码,是否有任何方法可以简单地排序,如
List<T>.OrderBy(o => o.x).ToList()....ETC
我想根据交付状态对整个列表进行排序[2]
var list = new List<string[]>();
list.Add(new string[] { "1", "zzz", "z" });
list.Add(new string[] { "1", "aaa", "x" });
list.Add(new string[] { "1", "b", "y" });
list.Add(new string[] { "1", "c", "3" });
var orderedList = list.OrderBy(e => e[2]);
看起来你有一个包含3个元素的数组,你想按每个数组的第三个元素排序:
// assuming List<string[]> allDeliveryStatuses;
var result = allDeliveryStatuses.OrderBy(d => d[2]).ToList();
边注:使用数组来表示数据结构是一个坏主意(但显然不应该是我的呼叫)