c# 4.0 - Check duplicate key in Hashtable before adding a key -


i have hashtable , want put check whether hashtable has key or not before adding key in hashtable. adding duplicate key in hashtable throwing exception. want override hashtable's virtual 'add' method , put check in it. dont know how can override add method.

please me write override method.

you can use containskey.

another way use item indexer-property adds new keys , updates existing.

var ht = new system.collections.hashtable(); ht["test"] = "foo"; // added ht["test"] = "bah"; // updated 

however, should consider replace old , redundant hashtable generic dictionary<tkey, tval>. why?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -