LINQ/C#: Where & Foreach using index in a list/array

Posted by Andrew White on Stack Overflow See other posts from Stack Overflow or by Andrew White
Published on 2010-06-06T11:46:35Z Indexed on 2010/06/06 11:52 UTC
Read the original article Hit count: 381

Filed under:
|
|
|

Hi,

I have a list/array and need to process certain elements, but also need the index of the element in the processing. Example:

List Names = john, mary, john, bob, simon
Names.Where(s => s != "mary").Foreach(MyObject.setInfo(s.index, "blah")

But cannot use the "index" property with lists, inversely if the names were in an Array I cannot use Foreach... Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ