Skip to content

Commit

Permalink
Use end index "[^1]"
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Nov 4, 2022
1 parent d684bf8 commit c88bba1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MoreLinq/AggregateRight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static TSource AggregateRight<TSource>(this IEnumerable<TSource> source,
if (list.Count == 0)
throw new InvalidOperationException("Sequence contains no elements.");

return AggregateRightImpl(list, list[list.Count - 1], func, list.Count - 1);
return AggregateRightImpl(list, list[^1], func, list.Count - 1);
}

/// <summary>
Expand Down
5 changes: 1 addition & 4 deletions MoreLinq/ScanRight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ public static IEnumerable<TSource> ScanRight<TSource>(this IEnumerable<TSource>
if (source == null) throw new ArgumentNullException(nameof(source));
if (func == null) throw new ArgumentNullException(nameof(func));

return ScanRightImpl(source, func,
list => list.Count > 0
? (list[list.Count - 1], list.Count - 1)
: ((TSource, int)?) null);
return ScanRightImpl(source, func, list => list.Count > 0 ? (list[^1], list.Count - 1) : null);
}

/// <summary>
Expand Down

0 comments on commit c88bba1

Please sign in to comment.