From 4aeb86e3f7fab1add6127aff9b40d8f3ff417a2c Mon Sep 17 00:00:00 2001 From: Mobile46 Date: Wed, 1 Nov 2023 10:43:52 +0300 Subject: [PATCH] Fix FirstOrDefault bug --- .../First/StructCollection.First.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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; }