public class MyHashtable : IDictionary, ICollection, IEnumerable
{
private Hashtable m_htKey2Val = null;
private Hashtable m_htVal2Key = null;
public MyHashtable ()
{
m_htKey2Val = new Hashtable();
m_htVal2Key = new Hashtable();
}
private MyHashtable (Hashtable ht)
{
m_htKey2Val = ht;
m_htVal2Key = new Hashtable();
foreach( object key in ht.Keys )
{
m_htVal2Key [ht[key]] = key;
}
}
public void Add( object key, object val )
{
m_htKey2Val.Add( key, val );
m_.htVal2Key. Add( val, key );
}
public void Remove( object key )
{
object val = m_htVal2Key [key];
m_htKey2Val .Remove( key );
m_htVal2Key .Remove( val );
}
//This ReverseLookup will do the job.
public object ReverseLookup( object val )
{
return m_htVal2Key [val];
}
// ....
}
Hashtable h1=new Hasttable();
h1.Add("k1","George");
MyHasTable hh= new MyHashtable(h1);
string s1 = (string)hh.ReverseLookup("George");