- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to skip elements from a sequence as long as the specified condition is true
Use the SkipWhile() method to skip elements from a sequence as long as the specified condition is true.
The following is the array −
int[] marks = { 35, 42, 48, 88, 55, 90, 95, 85 };
Here is the condition.
s => s >= 50
As long as the above condition is true, the elements above 50 are skipped as shown below −
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] marks = { 35, 42, 48, 88, 55, 90, 95, 85 }; // skips elements above 50 IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 50); // displays rest of the elements Console.WriteLine("Skipped marks > 60..."); foreach (int res in selMarks) { Console.WriteLine(res); } } }
Output
Skipped marks > 60... 48 42 35
Advertisements