Returning Index in Enumerable Select

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-03-29T16:15:55Z Indexed on 2010/03/29 16:23 UTC
Read the original article Hit count: 416

Filed under:
|
|
|
|

I have a List<MyClass> with 2 items which have a SequenceNumber property.

If I use this code below the returned index is 0 not 1:

var test = TrackingCollection
                .Where(x =>  x.SequenceNumber == 2)
                .Select((item, index) =>
                                    new
                                    {
                                         index, item.SequenceNumber
                                    });

Is this because that refers to 0 as the index in my new anonymous type or is it some zero index based weirdness that I just need to increment.

What I'm after is to return the index in TrackingCollection where the sequence number is 2 or 887 or any other correct index in the original collection...

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#3.0