I have a C# list of students. I cannot remove Item based on Id.
Program.cs
static void RemoveStudent(StudentManager studentManager)
{
Console.WriteLine("Which student? Insert ID:");
int id = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(id);
studentManager.RemoveStudent(1);
}
How student class looks like:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Major { get; set; }
}
How StudentManagerClass looks like:
public class StudentManager
{
private List<Student> students = new List<Student>();
public void RemoveStudent(int id)
{
students.RemoveAt(id);
}
Program exits without any prompt when trying to remove the element.
New contributor
Florea Păun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2