Thursday, July 7, 2011

How to find HashTable Key from HashTable value

Here is the code:

public class CustomHashtable:Hashtable
{
public CustomHashtable()
{
//
// TODO: Add constructor logic here
//
}

public bool ContainsValue(object Value, out int key)
{
if (this.ContainsValue(Value))
{
//iterate and get the key
foreach (int aKey in Keys)
{
if (this[aKey].Equals(Value)==true)
{
key=aKey;
return true;
}
}
}
else
{
key = -1;
return false;
}
key = -1;
return false;

}
}

No comments: