Retrieve Key from Value in Hash Table

by Prashant 16. December 2009 11:10

Working with hash tables is pretty simple but few days back I was having a problem in retrieving a key from a value in hash table. I was bit lazy to find a way myself, so I searched the net and here is what I got....a simple piece of code which lead to me to complete my task and so I thought I should share it with everyone here.

public string FindKey(string Value, Hashtable HT)
{
       string Key = "";
       IDictionaryEnumerator e = HT.GetEnumerator();
       while (e.MoveNext())
       {
            if (e.Value.ToString().Equals(Value))
            {
               Key = e.Key.ToString();
            }
       }
       return Key;
}

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: ,

C# | Code Snippets


Pingbacks and trackbacks (1)+

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Visit blogadda.com to discover Indian blogs Computers Blogs

About Me

Name of authorPrashant Khandelwal.
Programmer and tech enthusiast. More...

Feeds Subscribe Twitter Facebook Google Plus Linked In Delicious

Badges

MVB

MVP Blog Badge.

HTML5 Powered with CSS3 / Styling, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage

Month List

Blog Stats

414,259 Hits

Adverts

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Creative Commons License