【发布时间】:2010-11-08 10:05:04
【问题描述】:
我有一个字符串值列表,我想将其添加到哈希表或其他可以通过键/索引访问但无法实现的数组中。我有这个按我想要的方式工作,但它很丑
List<string> valueList = new List<string>();
valueList.Add("1");
valueList.Add("2");
valueList.Add("3");
Hashtable p = new Hashtable();
valueList.ForEach(delegate(string f) { p.Add(valueList.FindIndex(v => v == f), f); });
编辑:在詹姆斯提醒我列表将按索引返回值之后,我选择了一个列表,这就是我最终得到的结果
valueList.ForEach(f => sequenceList.Add(int.Parse(f)));
【问题讨论】:
-
你想在这里做什么?从列表中构建一个哈希表,将索引映射到键?
-
我很难看到你所做的事情的好处?如果您只是对其进行索引,为什么不将其保留为 List 呢?
-
已决定将其保留为列表,谢谢
标签: c# .net hashtable ienumerable enumeration