Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering of List<T> and other IEnumerables

Tags:

c#

ienumerable

Can one rely that enumerating on the items of a List is done by the order of their insertion?

Does anyone know what the spec says about that?

Thanks!

like image 581
Vit Avatar asked Dec 07 '22 02:12

Vit


1 Answers

This will depend on the implementation. Here's a nice overview of the different generic collections. As far as the List<T> implementation is concerned, enumerating will be done in the same order as elements have been added.

like image 116
Darin Dimitrov Avatar answered Dec 27 '22 13:12

Darin Dimitrov