C# 可查询 TakeLast() 方法
使用该TakeLast()方法从末尾获取指定数量的元素。
以下是我们的数组。
int[] pages = { 492, 290, 129, 602, 152 };现在,使用OrderBy按升序对元素进行排序。然后使用该TakeLast()方法从末尾获取指定数量的元素。
marks.AsQueryable().OrderByDescending(s => s).Take(5);
让我们看看完整的例子。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
//书页
int[] pages = { 492, 290, 129, 602, 152 };
//获取最后两本书的页面
IEnumerable last = pages.AsQueryable().OrderBy(s => s).TakeLast(2);
foreach (int res in last) {
Console.WriteLine(res);
}
}
} 输出结果492 602
热门推荐
10 中秋祝福语简短最新通用
11 给朋友除夕祝福语简短
12 家长送新兵祝福语简短
13 蛋糕祝福语公司文案简短
14 爱情春节祝福语简短精辟
15 送别宴蛋糕祝福语简短
16 小布老师祝福语毕业简短
17 考试专属祝福语大全简短
18 喜得麟儿的简短祝福语