使用该TakeLast()方法从数组末尾返回元素。
让我们首先声明并初始化一个数组。
int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};现在,让我们获取最后三个元素。
IEnumerable<int> units = prod.AsQueryable().TakeLast(3);
让我们看完整的代码。
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};
//最后三个产品的值
IEnumerable<int> units = prod.AsQueryable().TakeLast(3);
foreach (int res in units) {
Console.WriteLine(res);
}
}
}输出结果
698 765 789