Iteration Methods

G

Guest

Say I have a listbox and I need to go through each entry in the same order
that the are identified in the listbox. I know if I create my own counter an
manually update the counter as I process each item in the Listbox that I will
always process them in the order in which they are contained in the listbox.
If instead I used the "foreach" convention of iteration, can I be assured
that I will process them in the same order that they exists in the listbox?
 
G

Guest

Yes.
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected)
{
//do some processing
}
}
 
S

S.M. Altaf [MVP]

Hi Jim,

foreach depends upon the item counter in the Collection's implementation. I
believe the ListBoxItemCollection class assures you that they will be
processed in the same order as in the ListBox.

HTH,
Altaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top