我有关键和值的哈希表,在我的代码中,我通过以下值迭代哈希表:
foreach (Object clientObject in ClientList.Values)
{
// code to perform operation based on value
......
}
Run Code Online (Sandbox Code Playgroud)
ClientList是哈希表的位置.现在我想在我的代码中从哈希表中获取关键值.有没有办法实现这一目标?
谢谢
您必须以这种方式遍历表:
Hashtable clientList = new Hashtable();
foreach (DictionaryEntry dictionaryEntry in clientList)
{
// work with value.
Debug.Print(dictionaryEntry.Value.ToString());
// work with key.
Debug.Print(dictionaryEntry.Key.ToString());
}
Run Code Online (Sandbox Code Playgroud)