Ren
Ren

Reputation: 437

How do I remove an entry from List<KeyValuePair<string, string>> based on just the key?

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

Answers (1)

codekaizen
codekaizen

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

Related Questions