如何从哈希表中的值获取键

Upe*_*ari 5 c#

我有关键和值的哈希表,在我的代码中,我通过以下值迭代哈希表:

foreach (Object clientObject in ClientList.Values)
{
    // code to perform operation based on value
    ......
}
Run Code Online (Sandbox Code Playgroud)

ClientList是哈希表的位置.现在我想在我的代码中从哈希表中获取关键值.有没有办法实现这一目标?

谢谢

Fis*_*aen 5

您必须以这种方式遍历表:

        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)