C# 程式從末尾跳過陣列元素
宣告一個數組並初始化元素。
int[] marks = { 45, 50, 60, 70, 85 };使用 SkipLast() 方法跳過陣列元素,從末尾算起。
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
元素被跳過,剩餘元素返回如下所示 -
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] marks = { 45, 50, 60, 70, 85 };
Console.WriteLine("Array...");
foreach (int res in marks)
Console.WriteLine(res);
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
Console.WriteLine("Array after skipping last 3 elements...");
foreach (int res in selMarks)
Console.WriteLine(res);
}
}輸出
Array... 45 50 60 70 85 Array after skipping last 3 elements... 45 50
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP