2013-03-16 104 views
1

如何排序列表< T> []?排序或順序排序列表<T> [] c#使用Linq

我有列表List [] deliverystatus = new List [3];

 deliverystatus[0]---> stores name of file 
     deliverystatus[1]---> file delivery date 
     deliverystatus[2]---> where to delivery 

我轉換列表轉換成表格,並通過郵件發送。 我不能改變其他代碼有沒有什麼辦法來排序simplylike

 List<T>.OrderBy(o => o.x).ToList()....ETC 

我想基於deliverystatus排序整個名單[2]

回答

4
 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

看起來你有3個元素數組列表,您要訂購其項目由每個陣列的第三個組成部分:

// assuming List<string[]> allDeliveryStatuses; 
var result = allDeliveryStatuses.OrderBy(d => d[2]).ToList(); 

邊注:使用數組來表示數據結構是壞主意(但顯然不應該是我的電話)

+0

很好,爲什麼不能我這個想法。 – Civa 2013-03-16 07:21:31