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 724 B

12345678910111213141516171819202122232425262728
  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. #elif !NET6_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER
  13. #error Target framework not supported!
  14. #endif
  15. internal static IEnumerable<T> TakeLastImpl<T>(IEnumerable<T> source, int count)
  16. {
  17. var list = source.ToList();
  18. if (count >= list.Count)
  19. return list;
  20. list.RemoveRange(0, list.Count - count);
  21. return list;
  22. }
  23. }
  24. }