473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

foreach on Collection, List, IList, ICollection, ...

Hi all,

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.
Jun 27 '08 #1
3 7755
No... It would go index 0 then index 1, index 2, so on.....
"Dansk" <da***@laouilest.frwrote in message
news:Ot**************@TK2MSFTNGP04.phx.gbl...
Hi all,

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.
Jun 27 '08 #2
Dansk wrote:
Hi all,

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.
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
Jun 27 '08 #3

Thank you for your answers, they really make sense to me.
Dansk a écrit :
Hi all,

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.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hman | last post by:
Hi, I have a collection class where I've implemeneted the ICollection Interface. Here is a small code segment. public class PageList : ICollection, IComparer, IEnumerable, IList {
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
3
by: ad | last post by:
Hi, When I studied CSharp, I am confuse by IList, Collection and Array. What is the relationships between them?
6
by: rodchar | last post by:
hey all, Dim _oItems As Outlook.Items Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) _oItems = oInbox.Items I can iterate thru this with a...
3
by: Steve Barnett | last post by:
I have a collection which I need to navigate through in several different ways. Is there any way to structure my class such that I can have several different iterators? Ideally, I'd like to do...
5
by: Jimp | last post by:
Why can't I cast List<MyObject> to ICollection<IMyObject>. MyObject implements IMyObject, and of course, List implements ICollection. Thanks
5
by: Chuck Cobb | last post by:
I'm having a problem converting an array to a collection. The code I'm using looks like the following: CustomerInfo cArray; Collection<CustomerInfo> cCollection = new...
28
by: Michael Primeaux | last post by:
What is the recommended pattern for implementing a synchronized (thread-safe) class that inherits from Collection<T>? For example, I want to implement a SyncRoot property . I do see where I can...
6
by: Doug | last post by:
Hi, I want to create a collection of objects that will be used as a property of another object. So for example if I had a Customer object, I would like to have an AddressCollection property...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.