顺序列表根据阵列的信息排序
本文关键字:信息 排序 阵列 列表 顺序 | 更新日期: 2023-09-27 18:10:17
我想做的是根据数组中的信息重新排序数组列表。例如,我的列表可能有20个Long[]数组,我想按最高总aps和最低总时间排序。我尝试了几件事,但遇到了麻烦。任何帮助都将非常感激。
public List<long[]> Reorderedlist()
{
_timeKeeper._timeKeeperControls controls = new _timeKeeper._timeKeeperControls();
List<long[]> returnList = new List<long[]>();
List<long[]> listToReOrder = new List<long[]>();
listToReOrder = controls.teamInfoInClass("1",ContactlessTimer.Properties.Settings.Default.currentRaceID);
//newlist contains list of long[] arrays
//each array contains
//long[0] = id1 (eg 33)
//long[1] = id2 (eg 34)
//long[2] = totalLaps (eg 10)
//long[3] = total time (eg 340000 in miliseconds)
foreach (long[] Arr in listToReOrder)
{
foreach (long info in Arr)
{
//order
}
}
return returnList;
}
使用LINQ方法:OrderByDescending
和ThenBy
:
List<long[]> returnList = listToReOrder.OrderByDescending(x => x[2])
.ThenBy(x => x[3])
.ToList();