17/02/18 08:10:24.40 bn0z7G5m0.net
あえてLinqで書くならこうかな?でもこういう場合foreachで書く方が速いし自然だと思う
public static int Index<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
try
{
return source.Select((value, index) => new { Index = index, Value = value })
.First(item => predicate(item.Value)).Index;
}
catch (InvalidOperationException) { return -1; }
}