I.E. If I want to select from an array, is the resultant IEnumerable<object> object necessarily in order?
public class Student { public string FullName, ... }
public class School { public string Name, public Student[] Students, ... }
public void StudentListWork(School thisSchool)
{
IEnumerable<string> StudentNames = thisSchool.Students.Select(student => student.FullName);
// IS StudentNames GUARANTEED TO BE IN THE SAME ORDER AS thisSchool.Students?
}
Thanks!
Yes, in this case:
Enumerable.Selectreturns items in the order of the original sequence (after projection, of course)Some collections do not retain order, however. In particular:
HashSet<T>andDictionary<TKey, TValue>make no guarantees about the order in which values are returnedSortedSet<T>andSortedDictionary<TKey, TValue>apply guaranteed ordering based on the items placed within them