Is the result of List <T> .FindAll guaranteed in the same order as the original list?
5 answers
This is not guaranteed in the sense that he does not talk about it in the documentation, however, if you look at how this is currently implemented, then yes, it will always return in the same order.
Here's how it is currently implemented:
public List<T> FindAll(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
List<T> list = new List<T>();
for (int i = 0; i < this._size; i++)
{
if (match(this._items[i]))
{
list.Add(this._items[i]);
}
}
return list;
}
As you can see, this is a simple loop that sequentially goes through the list and adds elements that match.
+6