N
N
neitoo2022-01-22 12:57:23
C++ / C#
neitoo, 2022-01-22 12:57:23

How to implement change by id in List?

There is a list, but I don’t know how to determine the id of the students and change the students’ data when calling by id, how can this be done?

List<Student> students = new List<Student>()
  {
    new Student(){name = "Daniel", surname ="Page", age =19, kurs = "1", special = "IT"},
    new Student(){name = "Kimberly", surname ="Glover", age =18, kurs = "3", special = "IT"},
    new Student(){name = "Robert", surname =" Jackson", age =25, kurs = "5", special = "IT"},
    new Student(){name = "Sarah", surname ="Thomas", age =19, kurs = "1", special = "IT"},
  };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@insighter, 2022-01-22
@neitoo

student id (judging by your example) is a combination of the name + surname fields, the
search for such an id will be as follows:

var searchName = "значение для поиска";
var searchSurname = "значение для поиска";
var foundedStudent = students.Find(student => student.name == searchName && student.surname == searchSurnname);
if (foundedStudent != null){
  foundedStudent ... меняйте как хотите
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question