Use TakeWhile with index : TakeWhile « LINQ « C# / C Sharp






Use TakeWhile with index

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

public class MainClass{
   public static void Main(){
       int[] numbers = { 1, 3, 5, 4};
       var query = numbers.TakeWhile(( n, index) => n >= index);

       var query2 = numbers.SkipWhile(( n, index) => n >= index);
    }
}

 








Related examples in the same category

1.TakeWhile with condition
2.TakeWhile with expresion
3.TakeWhile with two parameters