Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
SkipWhile method in C#
SkipWhile skips an element when a condition is matched.
For example, use the following if you want to skip all even elements −
ele => ele %2 == 0
The following is an example wherein all the even elements are skipped and only the odd elements are displayed −
Example
using System.IO;
using System;
using System.Linq;
public class Demo {
public static void Main() {
int[] arr = { 20, 35, 55 };
Console.WriteLine("Initial array...");
foreach (int value in arr) {
Console.WriteLine(value);
}
// skipping even elements
var res = arr.SkipWhile(ele => ele % 2 == 0);
Console.WriteLine("New array after skipping even elements...");
foreach (int val in res) {
Console.WriteLine(val);
}
}
}
Output
Initial array... 20 35 55 New array after skipping even elements... 35 55
Advertisements
