424,054 Members | 1,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,054 IT Pros & Developers. It's quick & easy.

find index value of foreach

P: n/a
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;
}
}
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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;
}
}

Nov 20 '05 #2

P: n/a
you mean like this??

int j=0;
foreach (TextBox option in options)
{
int poll = optionList[j].PollId;
j++;
}
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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;
}
}


Nov 20 '05 #3

P: n/a
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.
Nov 20 '05 #4

P: n/a
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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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;
}
}

Nov 20 '05 #5

P: n/a
I don't like FORRRRRRRRRRRRRRRRRRRRRR
I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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;
}
}


Nov 20 '05 #6

P: n/a
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" <so**********@gmail.com> wrote in message
news:eZ**************@tk2msftngp13.phx.gbl...
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;
}
}

Nov 20 '05 #7

P: n/a
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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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;
> }
> }

Nov 20 '05 #8

P: n/a
hahaha

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .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;
>> }
>> }


Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.