find index value of foreach

Discussion in 'ASP .Net' started by mike, Nov 18, 2005.

  1. mike

    mike Guest

    what should i have to write in this code section?

    #### is what i want to write

    do i have to use foreach to for

    if options is TextBox array

    i used to enumbera....... but i don't remember...what is this??


    foreach (TextBox option in options)
    {
    if (option.Text.Length > 0)
    {
    int poll = kkk[ ##### ].PollId;
    }
    }
     
    mike, Nov 18, 2005
    #1
    1. Advertising

  2. mike

    Brock Allen Guest

    Use a traditional for loop.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > what should i have to write in this code section?
    >
    > #### is what i want to write
    >
    > do i have to use foreach to for
    >
    > if options is TextBox array
    >
    > i used to enumbera....... but i don't remember...what is this??
    >
    > foreach (TextBox option in options)
    > {
    > if (option.Text.Length > 0)
    > {
    > int poll = kkk[ ##### ].PollId;
    > }
    > }
     
    Brock Allen, Nov 18, 2005
    #2
    1. Advertising

  3. mike

    mike Guest

    you mean like this??

    int j=0;
    foreach (TextBox option in options)
    {
    int poll = optionList[j].PollId;
    j++;
    }


    "Brock Allen" <> wrote in message
    news:...
    > Use a traditional for loop.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >> what should i have to write in this code section?
    >>
    >> #### is what i want to write
    >>
    >> do i have to use foreach to for
    >>
    >> if options is TextBox array
    >>
    >> i used to enumbera....... but i don't remember...what is this??
    >>
    >> foreach (TextBox option in options)
    >> {
    >> if (option.Text.Length > 0)
    >> {
    >> int poll = kkk[ ##### ].PollId;
    >> }
    >> }

    >
    >
     
    mike, Nov 18, 2005
    #3
  4. mike

    intrader Guest

    On Sat, 19 Nov 2005 01:32:27 +0900, mike wrote:

    > what should i have to write in this code section?
    >
    > #### is what i want to write
    >
    > do i have to use foreach to for
    >
    > if options is TextBox array
    >
    > i used to enumbera....... but i don't remember...what is this??
    >
    >
    > foreach (TextBox option in options)
    > {
    > if (option.Text.Length > 0)
    > {
    > int poll = kkk[ ##### ].PollId;
    > }
    > }

    Go back to basics a bit. Please look up
    http://www.ondotnet.com/pub/a/dotnet/2004/06/07/liberty.html?page=last&x-maxdepth=0
    by Jesse Liberty.
     
    intrader, Nov 18, 2005
    #4
  5. mike

    Brock Allen Guest

    No, like this:

    for (int i = 0; i < options.Length; i++)
    {
    int poll = optionList[j].PollId;
    }

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > you mean like this??
    >
    > int j=0;
    > foreach (TextBox option in options)
    > {
    > int poll = optionList[j].PollId;
    > j++;
    > }
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> Use a traditional for loop.
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> what should i have to write in this code section?
    >>>
    >>> #### is what i want to write
    >>>
    >>> do i have to use foreach to for
    >>>
    >>> if options is TextBox array
    >>>
    >>> i used to enumbera....... but i don't remember...what is this??
    >>>
    >>> foreach (TextBox option in options)
    >>> {
    >>> if (option.Text.Length > 0)
    >>> {
    >>> int poll = kkk[ ##### ].PollId;
    >>> }
    >>> }
     
    Brock Allen, Nov 18, 2005
    #5
  6. mike

    mike Guest

    I don't like FORRRRRRRRRRRRRRRRRRRRRR
    I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``


    "Brock Allen" <> wrote in message
    news:...
    > No, like this:
    >
    > for (int i = 0; i < options.Length; i++)
    > {
    > int poll = optionList[j].PollId;
    > }
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >> you mean like this??
    >>
    >> int j=0;
    >> foreach (TextBox option in options)
    >> {
    >> int poll = optionList[j].PollId;
    >> j++;
    >> }
    >> "Brock Allen" <> wrote in message
    >> news:...
    >>
    >>> Use a traditional for loop.
    >>>
    >>> -Brock
    >>> DevelopMentor
    >>> http://staff.develop.com/ballen
    >>>> what should i have to write in this code section?
    >>>>
    >>>> #### is what i want to write
    >>>>
    >>>> do i have to use foreach to for
    >>>>
    >>>> if options is TextBox array
    >>>>
    >>>> i used to enumbera....... but i don't remember...what is this??
    >>>>
    >>>> foreach (TextBox option in options)
    >>>> {
    >>>> if (option.Text.Length > 0)
    >>>> {
    >>>> int poll = kkk[ ##### ].PollId;
    >>>> }
    >>>> }

    >
    >
     
    mike, Nov 18, 2005
    #6
  7. mike

    Guest Guest

    Unfortunately the IEnumerator interface that is used for the foreach only
    provides the methods Current, MoveNext and Reset. Without knowing what the
    options object is I can only assume it implements the following:



    int poll = kk[ options.IndexOf(option) ].PollId;



    This actually iterates through the list testing the equality using
    object.Equals(object2) in which case it may be just as quick to use a for
    loop:



    <ObjectItem> option;



    for(int i = 0; i < options.Count; i++)

    {

    option = options.Item;

    if(option.Text.Length >0)

    {

    int poll = kk.PollId;

    }

    }

    Setting the option var is optional in this case just depends on how much you
    want to access the object and if your happy typecasting.

    - Mike

    ---------------------------------------------------------------------------------
    <a href="http://www.cogitar.net"> Cogitar Software. (www.cogitar.net) </a>
    http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
    ---------------------------------------------------------------------------------

    "mike" <> wrote in message
    news:...
    > what should i have to write in this code section?
    >
    > #### is what i want to write
    >
    > do i have to use foreach to for
    >
    > if options is TextBox array
    >
    > i used to enumbera....... but i don't remember...what is this??
    >
    >
    > foreach (TextBox option in options)
    > {
    > if (option.Text.Length > 0)
    > {
    > int poll = kkk[ ##### ].PollId;
    > }
    > }
    >
     
    Guest, Nov 18, 2005
    #7
  8. mike

    Brock Allen Guest

    Sorry. If you don't like the for loop, then the the way you suggested will
    work fine.

    *shrug*

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > I don't like FORRRRRRRRRRRRRRRRRRRRRR
    > I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
    > "Brock Allen" <> wrote in message
    > news:...
    >
    >> No, like this:
    >>
    >> for (int i = 0; i < options.Length; i++)
    >> {
    >> int poll = optionList[j].PollId;
    >> }
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> you mean like this??
    >>>
    >>> int j=0;
    >>> foreach (TextBox option in options)
    >>> {
    >>> int poll = optionList[j].PollId;
    >>> j++;
    >>> }
    >>> "Brock Allen" <> wrote in message
    >>> news:...
    >>>> Use a traditional for loop.
    >>>>
    >>>> -Brock
    >>>> DevelopMentor
    >>>> http://staff.develop.com/ballen
    >>>>> what should i have to write in this code section?
    >>>>>
    >>>>> #### is what i want to write
    >>>>>
    >>>>> do i have to use foreach to for
    >>>>>
    >>>>> if options is TextBox array
    >>>>>
    >>>>> i used to enumbera....... but i don't remember...what is this??
    >>>>>
    >>>>> foreach (TextBox option in options)
    >>>>> {
    >>>>> if (option.Text.Length > 0)
    >>>>> {
    >>>>> int poll = kkk[ ##### ].PollId;
    >>>>> }
    >>>>>
     
    Brock Allen, Nov 18, 2005
    #8
  9. hahaha

    "Brock Allen" <> wrote in message
    news:...
    > Sorry. If you don't like the for loop, then the the way you suggested will
    > work fine.
    >
    > *shrug*
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    > > I don't like FORRRRRRRRRRRRRRRRRRRRRR
    > > I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
    > > "Brock Allen" <> wrote in message
    > > news:...
    > >
    > >> No, like this:
    > >>
    > >> for (int i = 0; i < options.Length; i++)
    > >> {
    > >> int poll = optionList[j].PollId;
    > >> }
    > >> -Brock
    > >> DevelopMentor
    > >> http://staff.develop.com/ballen
    > >>> you mean like this??
    > >>>
    > >>> int j=0;
    > >>> foreach (TextBox option in options)
    > >>> {
    > >>> int poll = optionList[j].PollId;
    > >>> j++;
    > >>> }
    > >>> "Brock Allen" <> wrote in message
    > >>> news:...
    > >>>> Use a traditional for loop.
    > >>>>
    > >>>> -Brock
    > >>>> DevelopMentor
    > >>>> http://staff.develop.com/ballen
    > >>>>> what should i have to write in this code section?
    > >>>>>
    > >>>>> #### is what i want to write
    > >>>>>
    > >>>>> do i have to use foreach to for
    > >>>>>
    > >>>>> if options is TextBox array
    > >>>>>
    > >>>>> i used to enumbera....... but i don't remember...what is this??
    > >>>>>
    > >>>>> foreach (TextBox option in options)
    > >>>>> {
    > >>>>> if (option.Text.Length > 0)
    > >>>>> {
    > >>>>> int poll = kkk[ ##### ].PollId;
    > >>>>> }
    > >>>>> }

    >
    >
     
    Patrick.O.Ige, Nov 18, 2005
    #9
    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. caldera
    Replies:
    1
    Views:
    4,406
    Scott Allen
    Feb 22, 2005
  2. Replies:
    1
    Views:
    21,132
  3. Tim Shoppa
    Replies:
    45
    Views:
    498
    Darren Dunham
    Dec 23, 2003
  4. ngoc
    Replies:
    5
    Views:
    179
    Tad McClellan
    May 11, 2006
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    306
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page