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
Post a Comment