C# Queryable SkipWhile() Method



Bypass elements in an array and return the remaining elements using the SkipWhile() method.

The following is our array −

int[] marks = { 45, 88, 55, 90, 95, 85 };

Now, let’s skip the elements greater than or equal to 60. The condition we have set using Lambda Expression.

IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).SkipWhile(s => s >= 60);

Example

 Live Demo

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);
      }
   }
}

Output

Skipped marks > 60...
55
45
Updated on: 2020-06-23T08:36:30+05:30

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements