简体   繁体   English

排序或排序以排序列表 <T> []使用Linq的c#

[英]Sort or order by to sort List<T>[] c# using Linq

How to Sort List< T >[] ? 如何排序列表<T> []?

i has list List[] deliverystatus = new List[3]; 我有列表List [] deliverystatus =新列表[3];

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

i convert list into table and send it by using mail. 我将列表转换成表格并通过使用邮件发送。 i cant change other code is there any way to sort simplylike 我无法更改其他代码,有什么办法可以简单地排序

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

i want sort entire list based on deliverystatus[2] 我想根据deliverystatus [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]);

It looks like you have list of 3 element arrays and you want to order its items by third component of each array: 看来您有3个元素数组的列表,并且想要按每个数组的第三个组件排序其项:

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

Side note: Using arrays to represent data structure is bad idea (but clearly should not be my call) 旁注:使用数组表示数据结构不是一个好主意(但显然不应该是我的电话)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM