2013-04-21 73 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