Reputation: 437
I have a KeyValurPair myList. How do I remove an entry based on the key? How should I use the myList.Remove method? I am not using a dictionary because need myList to be the Datasource of a Bindingsource.
List<KeyValuePair<string, string>> myList = new List<KeyValuePair<string, string>>();
string key = "@index";
.. .. ..
myList.Remove( i am lost here )
Thanks in adavnce, VRPS.
Upvotes: 2
Views: 3627
Reputation: 27419
Use List.RemoveAll. You can pass in a predicate which checks the key value. Example:
myList.RemoveAll(kvp => kvp.Key == "@index");
Upvotes: 1