Say we have a list of "A students", and a list of "B students". We then add both lists to a more generic list, called "students". Someone then decides to complicate our lives by adding a duplicate list of "A Students" to the generic "students" list. What's the most efficient way to remove one of the duplicate lists of "A students"? Note that there are two custom classes involved.
The generic students list in the code is called lstStudents. This is the list I would like to remove any duplicates from.
(I tried to come up with a better example, but this is the best I could do right now.)
I don't have to use LINQ, but it's available. MoreLinq is available as well.
Here are my classes:
public class Student
{
public Student(string _name, int _age, Exam _lastExam)
{
name = _name;
age = _age;
lastExam = _lastExam;
}
public string name { get; set; }
public int age { get; set; }
public Exam lastExam { get; set; }
}
public class Exam
{
public Exam(int _correct, int _possible)
{
correct = _correct;
possible = _possible;
}
public int correct { get; set; }
public int possible { get; set; }
}
And here's the code to create the mess:
List<List<Student>> lstStudents = new List<List<Student>>();
List<Student> lstAStudents = new List<Student>();
List<Student> lstDuplicateAStudents = new List<Student>();
List<Student> lstBStudents = new List<Student>();
// Create a list of some A students
lstAStudents.Add(new Student("Alex", 14, new Exam(98,100)));
lstAStudents.Add(new Student("Kim", 13, new Exam(96, 100)));
lstAStudents.Add(new Student("Brian", 14, new Exam(92, 100)));
lstStudents.Add(lstAStudents);
// Create a duplicate list of A students
lstDuplicateAStudents.Add(new Student("Alex", 14, new Exam(98, 100)));
lstDuplicateAStudents.Add(new Student("Kim", 13, new Exam(96, 100)));
lstDuplicateAStudents.Add(new Student("Brian", 14, new Exam(92, 100)));
lstStudents.Add(lstDuplicateAStudents);
// Create a list of some B students
lstBStudents.Add(new Student("John", 13, new Exam(88, 100)));
lstBStudents.Add(new Student("Jenny", 13, new Exam(80, 100)));
lstBStudents.Add(new Student("Jamie", 15, new Exam(81, 100)));
lstStudents.Add(lstBStudents);