与 列表 < > 按字母顺序订购类似,我们希望按一个元素排序,然后按另一个元素排序。我们希望实现
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 );
}
我们的清单如下:
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的解决方案。