If I've got a List with the following entries:
Apple Banana Grape Cherry Orange Kiwi
Is the result of
fruit.FindAll(f => f.Length == 6)
guaranteed to always be
Banana Cherry Orange
or could the order be different?
It's not guaranteed in the sense that it doesn't say it in the documentation, however if you look at how it's currently implemented, then yes, it'll always come back in the same order.
Here's how it's 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, it's a simple for loop that sequentially goes through the list, and adds the items that match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With