与List<> OrderBy Alphabetical Order类似,我们希望按一个元素排序,然后再按另一个元素排序.我们希望实现与
SELECT * from Table ORDER BY x, y
我们有一个类,它包含许多排序函数,并且通过一个元素进行排序没有问题
public class MyClass {
public int x;
public int y;
}
List<MyClass> MyList;
public void SortList() {
MyList.Sort( MySortingFunction );
}
我们的 list 如下:
Unsorted Sorted(x) Desired
--------- --------- ---------
ID x y ID x y ID x y
[0] 0 1 [2] 0 2 [0] 0 1
[1] 1 1 [0] 0 1 [2] 0 2
[2] 0 2 [1] 1 1 [1] 1 1
[3] 1 2 [3] 1 2 [3] 1 2
稳定排序更好,但不是必需的.这个解决方案对你有用.Net 2.0是受欢迎的.