Posts

Showing posts with the label lambda

C# Lambda expressions with Classes

C# Lambda expressions with Classes I am reading a csv with a list of students - Name, Surname, ClassLeader, Grade,Subject, Score. I want to add a new student if he doesn't exist or only add the Subject and Score if the student exists in the list. Code below: class School { private int Grades = new int[5] { 8, 9, 10, 11, 12 }; public List<Student> Students = new List<Student>(); private HashSet<string> AllSubjects = new HashSet<string>(); public School() { } public void CreateStudents() { List<string> storedCSVData = CSVHelper.ReadCSV(); //int index = 0; foreach(string lineItem in storedCSVData) { //index++; //if ((index % 6) != 0) // continue; string fullName = lineItem[0] + " " + lineItem[1]; int i = Students.IndexOf(x => ...