I have a List:
List<Student> allStudents = new List<Student>();
that contains over 94,000 Student objects, where Student is defined as:
public class Student
{
public Int32 ID { get; set; }
public String Surname { get; set; }
public String Other_Names { get; set; }
public String DOB { get; set; }
// remaining fields omitted
}
and sorted by Surname.
After grabbing a Student object from another source, I want to binary search the List allStudents to find a match based ONLY on the Surname property. For example, if an existing record in the List allStudents is:
Student(8139241, "Flintstone", "Fred", "12/1/1967")
and I search for the item:
Student(7294311, "Flintstone", "Wilma", "14/6/1969")
the binary search should be a success.
The List.BinarySearch(T, IComparer) overload appears to be a possibility, but is it a viable solution? Or is there a better strategy? I will be dealing a lot of records and searches, so O(n) search functions will not be viable.
Thanks in advance!
UPDATE: I've decided to replace my List with a MultiDictionary from the Wintellect PowerCollections library. This MultiDictionary can accept duplicate keys.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…