Skip from the first element divisible by 3 in CSharp
Description
The following code shows how to skip from the first element divisible by 3.
Example
using System;// w w w .j av a2 s. c o m
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass{
public static void Main() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var allButFirst3Numbers = numbers.SkipWhile(n => n % 3 != 0);
Console.WriteLine("All elements starting from first element divisible by 3:");
foreach (var n in allButFirst3Numbers) {
Console.WriteLine(n);
}
}
}
The code above generates the following result.