Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a Key from Dictionary by key name

I'm trying to remove a key from my dictionary if the key is a certain key.

parameterList is a dictionary<string,string>

parameterList.Remove(parameterList.Where(k => String.Compare(k.Key, "someKeyName") == 0));  
like image 922
PositiveGuy Avatar asked Feb 29 '12 06:02

PositiveGuy


People also ask

How do I remove a key from a list in Python?

How to Remove an Element from a List Using the remove() Method in Python. To remove an element from a list using the remove() method, specify the value of that element and pass it as an argument to the method. remove() will search the list to find it and remove it.


2 Answers

This should be enough:

parameterList.Remove(key); 
like image 193
Ufuk Hacıoğulları Avatar answered Sep 26 '22 08:09

Ufuk Hacıoğulları


Simply remove by key:

parameterList.Remove("someKeyName"); 

To check:

if (parameterList.Remove("someKeyName")) {     // key removed } else {     // dictionary doesn't contain the key } 
like image 42
Kirill Polishchuk Avatar answered Sep 24 '22 08:09

Kirill Polishchuk