I have to find the names passing through the parameter array in the List with lambda. Should I have to iterate for searching equal names from the array?
partial class StudentTestScoresProgram { static public List<Student> GetStudents() { List<Student> students = new List<Student> { new Student { Name = "Michael", Scores = new int[] { 94, 92, 91, 91 } }, new Student { Name = "Isabelle", Scores = new int[] { 66, 87, 65, 93, 86} }, new Student { Name = "Chastity", Scores = new int[] { 76, 61, 73, 66, 54} }, new Student { Name = "Chaim", Scores = new int[] { 94, 55, 82, 62, 52} }, new Student { Name = "Patience", Scores = new int[] { 91, 79, 58, 63, 55} }, new Student { Name = "Echo", Scores = new int[] { 74, 85, 73, 75, 86} }, new Student { Name = "Pamela", Scores = new int[] { 73, 64, 53, 72, 68} }, new Student { Name = "Anne", Scores = new int[] { 78, 96, 52, 79, 60} } }; return students; } /// <summary> /// Find a set of students and display their information /// /// You MUST use lambda or Predicate/delegate with FindAll for this. /// </summary> /// <param name="students">list of students</param> /// <param name="search">array of student names to find</param> static void FindStudents(List<Student> students, params string[] search) { //I have to fill the code in here. List<Student> subArray = students.FindAll(i => i.Name == search[]); //This is what I was thinking of } I have to fill the code, how can I search for an array?
The program is
static void Main(string[] args) { List<Student> students = GetStudents(); FindStudents(students, "Bruno", "Tanya", "Tony", "Sami"); FindStudents(students, "Xerxes"); } And the output should be like this
Searching for the following students: Bruno Tanya Tony Sami Found the following students: Name: Bruno, Scores: 62, 66, 70, 82 Name: Tanya, Scores: 60, 77, 88, 99 Searching for the following students: Xerxes Found the following students: https://stackoverflow.com/questions/65948122/c-sharp-find-a-set-of-objects-and-diplay-their-information-i-must-use-lambda-or January 29, 2021 at 10:49AM
没有评论:
发表评论