Let's say that I have a ConcurrentDictionary
:
var dict = new ConcurrentDictionary<string, someObject>();
dict.TryAdd("0_someA_someB_someC", obj0);
dict.TryAdd("1_someA_someB_someC", obj1);
dict.TryAdd("2_someA_someB_someC", obj2);
dict.TryAdd("3_someA_someB_someC", obj3);
The <number>_
in the keys is incremented and being a dictionary, there is no guarantee that the elements are in order.
Now, imagine I wanted to remove all items from the dictionary that have the number
less than 2
. I have no idea what the keys will look like, only that they will be prefixed with a number as above.
How can I remove all elements from the dictionary who's key starts with a value less than 2
?
For example, the resulting dict after this process will look like this:
dict.TryAdd("2_someA_someB_someC", obj2);
dict.TryAdd("3_someA_someB_someC", obj3);