In C# I'm trying to create a list of objects and when a new thing is added to the list, it is checked to make sure the same ID isn't used. I have the solution in Linq but I'm trying to do it without linq.
public void AddStudent(Student student)
{
if (students == null)
{
students.Add(student);
}
else
{
if ((students.Count(s => s.Id == student.Id)) == 1)
// LINQ query, student id is unique
{
throw new ArgumentException("Error student "
+ student.Name + " is already in the class");
}
else
{
students.Add(student);
}
}
}