In MyList
List<Person>
there may be a Person
with its Name
property set to "ComTruise". I need the index of first occurrence of "ComTruise" in MyList
, but not the entire Person
element.
What I'm doing now is:
string myName = ComTruise;
int thatIndex = MyList.SkipWhile(p => p.Name != myName).Count();
If the list is very large, is there a more optimal way to get the index?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…