【发布时间】:2014-04-02 20:16:00
【问题描述】:
我有一个哈希表,详细信息如下所述
public void get_Unique_Sequence(List<string> name, List<List<string>> nameSequence)
{
Hashtable test = new Hashtable();
test.Add(nameSequence, name)
foreach (DictionaryEntry entry in test)
{
Console.WriteLine("{0}: {1}", entry.Key, entry.Value);
}
}
我正在尝试在 foreach 循环的帮助下打印哈希表的内容。但是我得到的输出是
输出:
System.Collections.Generic.List`1[System.String]: System.Collections.Generic.List`1[System.String]
请指导我获取哈希表的键和值(即内容)。
【问题讨论】:
-
您必须将键和值转换为
List<string>并遍历它们以打印它们。List<T>的ToString()是“System.Collections.Generic.List`1[T]” -
这段代码在我看来很奇怪。我几乎看不到任何可以使用列表作为键的场景。你到底想达到什么目的?
-
HashTable自 .NET 2.0 起有效折旧。您应该改用Dictionary。
标签: c#