I have a list that looks like the following:
STUDENT: John, TEST ONE: A, TEST TWO: A, TEST THREE: D
STUDENT: Greg, TEST ONE: F, TEST TWO: B, TEST THREE: D
How can I delete the data for a specific student once the user inputs the name? I've tried doing the following but it doesn't work:
List<object> list = new List<object>(); // contains the list of students that
// were appended
Then, inside of a method here is some of the code that I wrote:
Console.Write("Enter the name of the student you want to remove: ");
string removedStudent = Console.ReadLine();
list.RemoveAll(s => s == removedStudent);
When the code runs and I input Greg
as the name of the student I want to remove, nothing happens. I print the list and Greg is still in the list. So, instead of printing like this:
STUDENT: John, TEST ONE: A, TEST TWO: A, TEST THREE: D
It still prints like:
STUDENT: John, TEST ONE: A, TEST TWO: A, TEST THREE: D
STUDENT: Greg, TEST ONE: F, TEST TWO: B, TEST THREE: D
Is there a way I can delete the entire row just by specifying the name of the student?
Edit:
Here is the part where I ask the user to input the student information:
class StudentsIO
{
public object getInput()
{
Console.Write("Enter student name: ");
string studentName = Console.ReadLine();
Console.Write("Enter test 1 score: ");
string test1 = Console.ReadLine();
Console.Write("Enter test 2: ");
string test2 = Console.ReadLine();
Console.Write("Enter test 3: ");
string test3 = Console.ReadLine()
Students students = new Students(studentName,test1,test2,test3);
return students;
}
}
Here's where I add students to the list:
StudentIO newStudent = new StudentIO();
object studentList = newStudent.getInput();
list.Add(studentList);