Reputation: 47743
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));
Upvotes: 41
Views: 83028
Reputation: 56162
Simply remove by key:
parameterList.Remove("someKeyName");
To check:
if (parameterList.Remove("someKeyName"))
{
// key removed
}
else
{
// dictionary doesn't contain the key
}
Upvotes: 35