Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get key from value in hash table

Tags:

c#

I have hashtable with key and values and in my code I am iterating hashtable through values like below :

foreach (Object clientObject in ClientList.Values)
{
    // code to perform operation based on value
    ......
}

Where ClientList is hashtable. Now I want to get key of perticualar value from hashtable in my code. is there any way to achieve that ?

Thanks

like image 652
Upendra Chaudhari Avatar asked Oct 20 '11 06:10

Upendra Chaudhari


1 Answers

You have to iterate through the table in this way:

        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());
        }
like image 199
Fischermaen Avatar answered Oct 07 '22 10:10

Fischermaen