Enumerable.TakeLast<TSource>(IEnumerable<TSource>, Int32) 方法

定义

返回一个新的可枚举集合,它包含 count 中的最后 source 个元素。

C#
public static System.Collections.Generic.IEnumerable<TSource> TakeLast<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, int count);

类型参数

TSource

可枚举集合中元素的类型。

参数

source
IEnumerable<TSource>

可枚举的集合实例。

count
Int32

从集合末尾算起获取的元素数。

返回

IEnumerable<TSource>

一个新的可枚举集合,它包含 count 中的最后 source 个元素。

例外

sourcenull

注解

如果 count 不是正数,此方法将返回一个空的可枚举集合。

适用于

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1