c# - How to check for duplicate keys and delete previous value from Dictionary? -


i have dictionary contains values keys. according condition, have duplicate keys strictly not permitted in dictionary. question is: how check previous duplicate key in current dictionary , delete add new?

you can use containskey() method of dictionary find out whether dictionary contains key or not

dict.containskey(key) 

it returns true if dictionary contains key otherwise returns false

you don't need delete key can overwrite value

if(dict.containskey(key)) { dict[key]=your_new_value; } else {  dict.add ( key,your_new_value); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -