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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -