diff --git a/src/StructLinq/First/StructCollection.First.cs b/src/StructLinq/First/StructCollection.First.cs index c55a7e62..313cec2e 100644 --- a/src/StructLinq/First/StructCollection.First.cs +++ b/src/StructLinq/First/StructCollection.First.cs @@ -105,9 +105,12 @@ public static bool TryFirst(this TCollection collec return false; for (int i = 0; i < collection.Count; i++) { - first = collection.Get(i); - if (predicate(first)) + var current = collection.Get(i); + if (predicate(current)) + { + first = current; return true; + } } return false; } @@ -120,9 +123,12 @@ public static bool TryFirst(this IStructCollection(this TCollection return false; for (int i = 0; i < collection.Count; i++) { - first = collection.Get(i); + var current = collection.Get(i); if (predicate.Eval(first)) + { + first = current; return true; + } } return false; }