Edit List <Tuple> item

With List<String> you can edit an element simply with this:

 var index = List.FindIndex(s => s.Number == box.Text); List[index] = new String; 

But how to apply it to List<Tuple<string, string>> for example?

+6
source share
2 answers
 var tuple = List.Find(s => s.Item1 == box.Text); //assuming you're searching for the first string, but you can change the predicate anyway. tuple = new Tuple<string, string>(new String, tuple.Item2); 

As mentioned in another answer, you can also use an index, but you can also just find the object and update it, which should work too.

+4
source

You can find the index in the same way - by applying a condition to each tuple from the list:

 var index = listOfTuples.FindIndex(t => t.Item1 == box1.Text || t.Item2 == box2.Text); 

You can replace an element by calling Tuple.Create :

 listOfTuples[index] = Tuple.Create(box3.Text, box4.Text); 
+7
source

Source: https://habr.com/ru/post/976234/


All Articles