johnkainn
asked on
foreach index
When using foreach is it possible to get the index of the loop when certain condition become true?
For example:
foreach(MyObject o in oList){
if(o.Id==5){
//Find index of the oList
}
}
For example:
foreach(MyObject o in oList){
if(o.Id==5){
//Find index of the oList
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@p_Davis,
Perhaps I misunderstand your addition, but what the author was trying to do is obtain the index within the foreach iteration he provided in his example loop. Within that loop, as I had shown, there is not a way to get the index of oList to which o belongs. What I suggested he do, instead, was pretty much what you suggested.
Are we in agreement?
Cheers,
Jon
Perhaps I misunderstand your addition, but what the author was trying to do is obtain the index within the foreach iteration he provided in his example loop. Within that loop, as I had shown, there is not a way to get the index of oList to which o belongs. What I suggested he do, instead, was pretty much what you suggested.
Are we in agreement?
Cheers,
Jon
i need this holiday break =)
it appears we are in agreement.
it appears we are in agreement.
:)
Have a happy, healthy one.
Cheers,
Jon500
Have a happy, healthy one.
Cheers,
Jon500
Maybe i am misunderstanding?
i put together a little project with the loading of a list of MyObject and then a little loop that grabs the index of each object in that list.
Open in new window