Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > find index value of foreach

Reply
Thread Tools

find index value of foreach

 
 
mike
Guest
Posts: n/a
 
      11-18-2005
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;
}
}


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      11-18-2005
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;
> }
> }



 
Reply With Quote
 
 
 
 
mike
Guest
Posts: n/a
 
      11-18-2005
you mean like this??

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


"Brock Allen" <> wrote in message
news: .com...
> 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;
>> }
>> }

>
>



 
Reply With Quote
 
intrader
Guest
Posts: n/a
 
      11-18-2005
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...t&x-maxdepth=0
by Jesse Liberty.
 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      11-18-2005
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: .com...
>
>> 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;
>>> }
>>> }



 
Reply With Quote
 
mike
Guest
Posts: n/a
 
      11-18-2005
I don't like FORRRRRRRRRRRRRRRRRRRRRR
I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``


"Brock Allen" <> wrote in message
news: .com...
> 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: .com...
>>
>>> 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;
>>>> }
>>>> }

>
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      11-18-2005
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[i];

if(option.Text.Length >0)

{

int poll = kk[i].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;
> }
> }
>



 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      11-18-2005
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: .com...
>
>> 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: .com...
>>>> 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;
>>>>> }
>>>>>



 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      11-18-2005
hahaha

"Brock Allen" <> wrote in message
news: .com...
> 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: .com...
> >
> >> 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: .com...
> >>>> 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;
> >>>>> }
> >>>>> }

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
value of performance index and reliability index Matt Schneyer Windows 64bit 10 11-20-2008 01:50 AM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
List Util insert_at(index, value), delete_at(index) ngoc Perl Misc 5 05-11-2006 12:31 PM
How to add index to ForEachTag (c:forEach as Java)? javaguy@sbcglobal.net Java 1 04-05-2005 03:01 PM
Idiom for array index that I'm foreach'ing over? Tim Shoppa Perl Misc 45 12-23-2003 04:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57