I have a object:
public class MyObject
{
int id;
string value;
}
I also have a list:
List<MyObject> list = new List<MyObject>;
for(int i=0;i;i<100000;i++)
{
list.Add(new MyObject(i, string.Format("Item {0}", i));
}
And list will be:
1, "Item 1"
2, "Item 2"
....
99999, "Item 99999"
This list is a sorted list which sorted on ID field. Note this is an example to describe a sorted list, it is not simple like the above example.
I want to find a item of ordered list based on ID field. I don’t know .NET Framework has support quickly search on a ordered list without enumerating.
I am interested in performance because of a big list. Thanks.
Best regards.
You can use a binary search for this.
You can use the built-in implementation, providing a custom
IComparer<T>that compares on your type’sidproperty: