Iteration Methods

Discussion in 'ASP .Net' started by =?Utf-8?B?SmltIEhlYXZleQ==?=, Nov 17, 2005.

  1. 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?
     
    =?Utf-8?B?SmltIEhlYXZleQ==?=, Nov 17, 2005
    #1
    1. Advertising

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

    --
    [note: if this post answers your question, you can mark it as an answer
    using the web-based newsreader functions]
    -----
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Jim Heavey" wrote:

    > 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?
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 17, 2005
    #2
    1. Advertising

  3. 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


    --------------------------------------------------------------------------------
    All that glitters has a high refractive index.
    www.mendhak.com


    "Jim Heavey" <> wrote in message
    news:...
    > 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?
     
    S.M. Altaf [MVP], Nov 17, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo
    Replies:
    1
    Views:
    543
    Scott Allen
    Jan 7, 2005
  2. Raymond Hettinger

    Pre-PEP: reverse iteration methods

    Raymond Hettinger, Sep 24, 2003, in forum: Python
    Replies:
    34
    Views:
    868
    Stephen Horne
    Sep 25, 2003
  3. Raymond Hettinger

    Comment on PEP-0322: Reverse Iteration Methods

    Raymond Hettinger, Sep 25, 2003, in forum: Python
    Replies:
    59
    Views:
    1,043
    Stephen Horne
    Sep 29, 2003
  4. Rudi
    Replies:
    5
    Views:
    5,236
  5. Kenneth McDonald
    Replies:
    5
    Views:
    356
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page