【发布时间】:2012-10-31 05:13:28
【问题描述】:
我现在有 2 个列表:
list<string> names;
list<int> numbers;
我需要根据数字中的值对我的名字进行排序。 我一直在搜索,大多数都使用 x.ID 之类的东西,但我真的不知道那个值是什么。所以这没有用。
有谁知道,该怎么做,或者可以在 ID 部分帮助我吗?
【问题讨论】:
-
为什么一个信息需要两个列表?请改用
Dictionary<int,string>。 -
@TimSchmelter 一个普通的
Dictionary<,>不会按键排序(它使用哈希码)。听起来更像是SortedDictionary<int, string>或SortedList<int, string>。我提供了一个答案,描述了如何将两个列表转换成那个。