Binary Search a List of custom data types to match just one field

前端 未结 4 1639
清酒与你
清酒与你 2021-01-21 15:07

I have a List:

List allStudents = new List(); 

that contains over 94,000 Student objects, where Student is define

4条回答
  •  一个人的身影
    2021-01-21 15:31

    It has the following limitation

    1. If the List contains more than one element with the same value, the method returns only one of the occurrences, and it might return any one of the occurrences, not necessarily the first one.
    2. The List must already be sorted according to the comparer implementation; otherwise, the result is incorrect.

    I would suggest you to use Linq to find the Matching Data from your list.

      var data = students.where(o => o.SurName='xxxxx');
    

    > You can also use the Find or FindAll methods from the List object using predicates.

提交回复
热议问题