How can I find the index of an item in a list without looping through it?

Currently this doesn’t look very nice – searching through the list for the same item twice, just to get the index:

var oProp = something;

int theThingIActuallyAmInterestedIn = myList.IndexOf(myList.Single(i => i.Prop == oProp));

8 Answers
8

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *