本文介绍了按关系对两个列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我可以对两个列表或两个向量进行排序,即我对一个列表(距离)进行排序,并根据她的顺序对另一个列表进行排序,该列表使我保持索引.谢谢.

As I can sort two lists or two vectors, ie I sort a list (distances) and according to her order as I ordered another list that keeps me indexes.Thanks.

Pd.我正在研究Net Framework 2.0

Pd. I'm working on Net framework 2.0

List1          List2
[0]=125        [0]=1
[1]=130        [1]=2
[2]=124        [2]=3
[3]=128        [3]=4

对List1排序后,我想要

After Sorting List1 i want this

List1          List2
[0]=124        [0]=3
[1]=125        [1]=1
[2]=128        [2]=4
[3]=130        [3]=2

Pd.我的清单有2000条记录...

Pd. My list has 2000 records...

我可以做什么? ks ..

as I can do? thks..

推荐答案

List<decimal> scores = GetScores();
List<Fruit> fruit = GetFruit();

List<Tuple<decimal, Fruit>> sortedPairs = scores
  .Zip(fruit, (s, f) => Tuple.Create(s, f))
  .OrderBy(x => x.Item1)
  .ToList();

scores = sortedPairs.Select(x => x.Item1).ToList();
fruit = sortedPairs.Select(x => x.Item2).ToList();

现在您所要做的就是实现Zip,OrderBy,Select,ToList和Tuple.

Now all you have to do is implement Zip, OrderBy, Select, ToList and Tuple.

这篇关于按关系对两个列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 16:55