## 如何通过对象中的一个列表对另一个列表进行排序？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (46)

`ListClass.Add(new item_util(items[b], util[b]));`

`List<item_util> SortedList = ListClass.OrderBy(o=>o.items).ToList();`

```int[] items = {7,4,1};
int[] util = {5,11,20};
var listA = new List<int> {5,4,1,2,7,3,8,6};
List<item_util> ListClass= new List<item_util>();
for (int b = 0; b < items.Length; b++)
{
}
List<item_util> SortedList = ListClass.OrderBy(o => o.item).ToList();```

### 2 个回答

```using System;
using System.Linq;

namespace CustomSortDemo
{
class Program
{
static void Main(string[] args)
{
var listA = new[] { 5, 4, 1, 2, 7, 3, 8, 6 };
var listClass = new[] { (1, 20), (4, 11), (7, 5) };

foreach (var item in listClass.OrderBy(i => Array.IndexOf(listA, i.Item1)))
Console.WriteLine(item);
}
}
}```

```List<item_util> SortedList = ListClass.
OrderBy(o => Array.IndexOf(listA, o.PropertyOfTheValueInitem_utilFromItemsArray)).ToList();```

```    var listA = new int [] {5,4,1,2,7,3,8,6};
var listB = new List<ListClass>
{
new ListClass(1,20),
new ListClass(4,11),
new ListClass(7,5)
};
var results = listB.OrderBy
(
p => Array.IndexOf(listA, p.X)
);
foreach (var r in results) Console.WriteLine("{0},{1}", r.X, r.Y);```

```4,11
1,20
7,5```