I have a list<> of int arrays created like this
我有一个像这样创建的int数组的列表<>
List<uint[]> onMinterm = new List<uint[]>();
and it has got 1000 members. Every list members has 3 unsigned integers, I add my arrays just like that
它有1000个成员。每个列表成员都有3个无符号整数,我像这样添加数组
uint[] sayi= new uint[3];
sayi[0] = 34432; sayi[1] = 63533; sayi[2] = 12;
onMinterm.Add(sayi);
I want to sort my 1000 list (onMinterm
) according to each 3rd member (sayi[2]
). List will be sorted in decending order. Sample member should be at the end as its 3rd value is very small like 12.
我想根据每一个成员(sayi[2])对我的1000个列表进行排序(onMinterm)。列表将按顺序排列。样本成员应该在最后,因为它的第三个值很小,像12。
2 个解决方案
#1
3
I want to sort my 1000 list (
onMinterm
) according to each 3rd member (sayi[2]
). List will be sorted descending.我想根据每一个成员(sayi[2])对我的1000个列表进行排序(onMinterm)。列表将按降序排序。
You can do this, if you are ok with getting an IOrderedEnumerable
as the result.
您可以这样做,如果您可以得到一个IOrderedEnumerable作为结果。
var ordered = onMinterm.OrderByDescending(x => x[2]);
If you want to do an in-place sort:
如果你想进行就地排序:
onMinterm.Sort((x1, x2)=> x2[2].CompareTo(x1[2]));
#2
1
You can sort a List<> in place.
您可以对<>的列表进行排序。
class IntArrayComparer : IComparer<int[]>
{
public int Compare(T left, T right)
{
return right[2].CompareTo(left[2]);
}
}
myList.Sort(new IntArrayComparer());
#1
3
I want to sort my 1000 list (
onMinterm
) according to each 3rd member (sayi[2]
). List will be sorted descending.我想根据每一个成员(sayi[2])对我的1000个列表进行排序(onMinterm)。列表将按降序排序。
You can do this, if you are ok with getting an IOrderedEnumerable
as the result.
您可以这样做,如果您可以得到一个IOrderedEnumerable作为结果。
var ordered = onMinterm.OrderByDescending(x => x[2]);
If you want to do an in-place sort:
如果你想进行就地排序:
onMinterm.Sort((x1, x2)=> x2[2].CompareTo(x1[2]));
#2
1
You can sort a List<> in place.
您可以对<>的列表进行排序。
class IntArrayComparer : IComparer<int[]>
{
public int Compare(T left, T right)
{
return right[2].CompareTo(left[2]);
}
}
myList.Sort(new IntArrayComparer());