I am currently building a data structure which relies a lot on efficiency.
Can anyone provide me with resources on how the Find(item => item.X = myObject.Property) method actually works?
Does it iterate linearly throughout all elements until it finds the element?
And what if I know the index of myObject and I use ElementAt(index)?
Which will be the most efficient of these two please?
From the
MSDN documentation on List<T>.FindI imagine that
ElementAtis optimized forIListand will do a direct index. But since you’re apparently using this object from theListconcrete type anyway, why not just do a direct index? Like this:If you already know the index, there is no point to searching. Just go straight to it.