For example:
List<MyClass> myList = new List<MyClass>();
...
// add lots of members...
...
MyClass myClass = myList[25];
Will asking for index 25 take much longer than asking for index 1, or does it use some quick algorithm to jump straight to the 25th item?
Thanks!
Internally
List<T>is implemented as array (which grows when you’re adding new items) so accessing of n-th element will be O(1) operation. (Therefore there will be no difference in speed between gettingmyList[1]andmyList[25].)Excerpt from the
List<T>.Itemproperty documentation:I can imagine how slow would be .NET applications if
List<T>had to jump through all items before getting n-th…