diff --git a/MoreLinq/CountDown.cs b/MoreLinq/CountDown.cs index a46186a89..1f5f72dad 100644 --- a/MoreLinq/CountDown.cs +++ b/MoreLinq/CountDown.cs @@ -65,15 +65,11 @@ public static IEnumerable CountDown(this IEnumerable sou IEnumerable IterateList(IListLike list) { - var countdown = Math.Min(count, list.Count); + var listCount = list.Count; + var countdown = Math.Min(count, listCount); - for (var i = 0; i < list.Count; i++) - { - var cd = list.Count - i <= count - ? --countdown - : (int?) null; - yield return resultSelector(list[i], cd); - } + for (var i = 0; i < listCount; i++) + yield return resultSelector(list[i], listCount - i <= count ? --countdown : null); } IEnumerable IterateCollection(int i)