C# Queryable SkipWhile() 方法
使用 SkipWhile() 方法,繞過陣列中的某些元素並返回剩餘元素。
下面是我們的陣列 −
int[] marks = { 45, 88, 55, 90, 95, 85 };現在,我們跳過大於或等於 60 的元素。我們使用 Lambda 表示式設定了條件。
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 60);
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] marks = { 45, 88, 55, 90, 95, 85 };
// skips elements above 60
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 60);
// displays rest of the elements
Console.WriteLine("Skipped marks > 60...");
foreach (int res in selMarks) {
Console.WriteLine(res);
}
}
}輸出
Skipped marks > 60... 55 45
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP