C# 程序可从数组末尾返回特定数量的元素
使用 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};
// value of last three products
IEnumerable<int> units = prod.AsQueryable().TakeLast(3);
foreach (int res in units) {
Console.WriteLine(res);
}
}
}输出
698 765 789
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP