2013-04-21 46 views
0

我想要做的是通过数组中的信息重新排列数组的列表。例如,我的列表可能有20个Long []数组,我想按最高总计和最低总时间排序虽然遇到了麻烦,但尝试了几件事。任何帮助将不胜感激。按数组中的信息排列数组的列表?

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; 
} 

回答

2

使用LINQ方法:OrderByDescendingThenBy

List<long[]> returnList = listToReOrder.OrderByDescending(x => x[2]) 
             .ThenBy(x => x[3]) 
             .ToList(); 
+0

感谢堆花了这么多时间未定答案似乎很简单。你能解释一下它是如何工作的吗?你为什么使用值2和3? – 2013-04-21 15:04:28