If you have List<T> , see the accepted answer .
If you have IEnumerable (or another collection that implements it) instead of List , you can use the following LINQ code:
int index = PartialValues.TakeWhile(partialPrefix=> ! wholeValue.StartsWith(partialPrefix)).Count();
Note the negation operator (!) In the lambda expression: the lambda expression should return true for elements that DO NOT match your condition.
The code returns the number of elements (for example, the index will indicate the position immediately after the last element) if no elements match the condition.
source share