IE。如果我想从数组中选择,结果是IEnumerable<object>
对象一定是按顺序排列的吗?
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.Select http://msdn.microsoft.com/en-us/library/bb534869.aspx按原始序列的顺序返回项目(当然是在投影之后)
有些集合确实not然而,保持秩序。尤其:
- 集合例如
HashSet<T>
and Dictionary<TKey, TValue>
不保证返回值的顺序
- 集合例如
SortedSet<T>
and SortedDictionary<TKey, TValue>
根据其中放置的物品应用保证订购
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)