Can I assume that when I loop throw a Collection, List, IList,
ICollection, ... by using foreach, I first get the element of index 0,
then index 2, and so on until the last one ?
Thanks for your answers,
Dansk.
"Dansk" <da...@laouilest.fr> wrote in message
news:Otc4ovst...@TK2MSFTNGP04.phx.gbl...
If you are really that concerned about it starting at 0 then I would suggest
using a for loop instead.
"Dansk" <da...@laouilest.fr> wrote in message
news:Otc4ovst...@TK2MSFTNGP04.phx.gbl...
Alternatively, consult the documentation for whatever collection you're
looking at. For instance, the documentation for List<T> makes it fairly
clear that you'll get the results in the natural order.
I can't remember ever being in a situation where a collection *had* a
natural order but didn't return the elements in that order from the
iterator. The benefits to readability of using foreach outweigh the
conservatism in this case, IMO.
--
Jon Skeet - <sk...@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Yes, you can expect this. This is an elementary requirement of the enumerator functionality.
--
Try Code-Navigator on http://www.codenav.com
a source code navigating, analysis and developing tool.
It supports following languages:
* C/C++
* Java
* .NET (including CSharp, VB.Net and other .NET components)
* Classic Visual Basic
* PHP, HTML, XML, ASP, CSS
* Tcl/Tk,
* Perl
* Python
* SQL,
* m4 Preprocessor
* Cobol
Dansk a écrit :