Say I have List<Foo> foos where the current order of elements is important. If I then apply a LINQ Enumerable method such as GroupBy, Where or Select, can I rely on the resulting IEnumerable<Foo> to iterate in the same relative order as the original list?
Say I have List<Foo> foos where the current order of elements is important. If
Share
Yes, for
Enumerablemethods (LINQ to Objects, which applies toList<T>you mentioned), you can rely on the order of elements returned bySelect,Where, orGroupBy. This is not the case for things that are inherently unordered likeToDictionaryorDistinct.This is not necessarily true for
IQueryableextension methods (other LINQ providers).