find index value of foreach

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

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;
}
}
 
you mean like this??

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


Brock Allen said:
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;
}
}
 
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++;
}
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;
}
}
 
I don't like FORRRRRRRRRRRRRRRRRRRRRR
I really wanna using FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``


Brock Allen said:
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++;
}
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;
}
}
 
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
 
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
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++;
}
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;
}
 
hahaha

Brock Allen said:
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
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++;
}
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;
}
}
 

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

Back
Top