You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IEnumerableExtensions.cs 626 B

1234567891011121314151617181920212223242526
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace LLama.Extensions
  4. {
  5. internal static class IEnumerableExtensions
  6. {
  7. #if NETSTANDARD2_0
  8. public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count)
  9. {
  10. return TakeLastImpl(source, count);
  11. }
  12. #endif
  13. internal static IEnumerable<T> TakeLastImpl<T>(IEnumerable<T> source, int count)
  14. {
  15. var list = source.ToList();
  16. if (count >= list.Count)
  17. return list;
  18. list.RemoveRange(0, list.Count - count);
  19. return list;
  20. }
  21. }
  22. }