在这个问题之后,另一个问题立即出现了。如果一个键在一个哈希表中有多个值,怎么能一次全部显示出来呢?
我的代码:
Hashtable graph = new Hashtable();
graph["my"] = new[] { "alice", "bob", "claire" };
graph["bob"] = new[] { "anuj", "peggy" };
graph["alice"] = new[] { "peggy" };
foreach (var element in graph.Keys)
{
Console.WriteLine(element + " friends is " + graph[element]);
}

或者
但总的来说,最好使用
Hastable类型化集,例如,Dictionary<string, string[]>