I have a 3-tuple List<Tuple>
with string, string, string
.
Initialization:
List<Tuple<string, string string>> myTupleList = new List<Tuple<string, string, string>>();
I basically want to search for a value in Item2
and remove the whole entry if found.
Let me visualize. If I have:
Item1 | Item2 | Item3
---------------------
"bar" | "foo" | "baz"
---------------------
"cat" | "dog" | "sun"
---------------------
"fun" | "bun" | "pun"
I want doing
//pseudocode
myTupleList.Remove("dog" in Item2);
To make the List
Item1 | Item2 | Item3
---------------------
"bar" | "foo" | "baz"
---------------------
"fun" | "bun" | "pun"
Have a look at the RemoveAll
method of List<T>
. It lets you remove an item based on a predicate.
For example, you can check just the Item2
property, as you said in your question:
myTupleList.RemoveAll(item => item.Item2 == "dog");
Note that (as implied by the method name) this will remove all elements that match this condition. Hence, if there are several elements whose Item2
property equals "dog"
, all of them will be removed.
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