我将值列表添加到排序列表中。问题是它没有正确地将数据添加到我的排序列表中。
public static void newList(List<string> oldList, List<string> headers)
{
var noHeaders = removeHeaders(oldList, headers);
SortedList<string, string> newList = new SortedList<string, string>();
for (int i = 0; i < headers.Count; i++)
{
newList.Add(headers[i], "placeholder");
}
//foreach (string header in headers)
//{
// newList.Add(header, "placeholder");
//}
上面是我的代码片段,我尝试了所有不同类型的循环,结果相同。
来自&#34;标题的数据&#34;列表看起来像这样:
[0]Value1
[1]Value2
[2]Value3
[3]Value4
当我将相同的数据添加到排序列表中后,当它看起来像这样:
[0]Value2
[1]Value1
[2]Value4
[3]Value3
任何人都可以向我解释为什么会这样,以便我可以解决它吗?我已经四处搜索了一下,但找不到任何有用的东西。
谢谢