Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0418 SkipWhile

Input: IEnumerable<TSource> Lamdda expression: TSource => bool or (TSource,int) => bool SkipWhile enumerates the input sequence, ignoring each item until the given predicate is false. It then emits the remaining elements: using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] numbers = { 3, 5, 2, 7, 4, 1 }; var skipWhileSmall = numbers.SkipWhile(n => n < 5); foreach(int s in skipWhileSmall){ Console.WriteLine(s); } } } The output: 5 2 7 4 1 SkipWhile with Lambda using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] names = { "Java", "C#", "Javascript", "SQL", "Oracle", "Python", "C++", "C", "HTML", "CSS" }; IEnumerable<string> query = names.SkipWhile(n => n.Length < 5); foreach(String s in query){ Console.WriteLine(s); } } } The output: Javascript SQL Oracle Python C++ C HTML CSS