I have a dictionary
private readonly Dictionary<string, WebResponse> _myDictionary;
Lets assume I have 10 values in the dictionary currently. I can able to add some values into it also I can delete the values based on the key present in the dictionary similar to below.
Remove:
_myDictionary.Remove(Key);
where key is a string variable.
Is that possible to delete more than one key at a time if the values matches for more than one key. I have keys like {KAAR1, KAAR2, KAAR3, ABCDEF}. Now I need to delete all the keys which contains "KAAR". Is that possible to do.
Kindly help.
Try this:
_myDictionary
.Where(x => x.Key.Contains("KAAR"))
.ToList()
.ForEach(kvp => _myDictionary.Remove(kvp.Key));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With