find index value of foreach

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;
}
}
 
M

mike

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.


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

intrader

B

Brock Allen

No, like this:

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


you mean like this??

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

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;
}
}
 
M

mike

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;
}


you mean like this??

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


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;
}
}
 
G

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
 
B

Brock Allen

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

*shrug*


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

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


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;
}
 
P

Patrick.O.Ige

hahaha

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

*shrug*


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;
}

you mean like this??

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


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

Members online

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top