I\'d like to use the LINQ TakeWhile function on LINQ to Objects. However, I also need to know the first element that \"broke\" the function, i.e. the first elem
I think you can use SkipWhile, and then take the first element.
var elementThatBrokeIt = data.SkipWhile(x => x.SomeThing).Take(1);
UPDATE
If you want a single extension method, you can use the following:
public static IEnumerable MagicTakeWhile(this IEnumerable data, Func predicate) {
foreach (var item in data) {
yield return item;
if (!predicate(item))
break;
}
}