TakeWhile and Take functions

Ddd
Posted by Ddd under LINQ category on | Points: 40 | Views : 1883
//TakeWhile is used to evaluate on the basis of some condition by using a Lambda expression.
//In this example, numbers less than 40 will be evalued till 40 is found. after 40, the numbers < 40
//will be ignored

//Take is just used to evaluate the data (say how many values) from any given point in the array.

using System;
using System.Linq;

class opr
{
static void Main()
{
int[] arr={10, 25,20,30,38,40,39,35,65};
var p=arr.TakeWhile(a=>a<40);
Console.WriteLine("---takewhile--");
foreach(var z in p)
{
Console.WriteLine(z);
}
Console.WriteLine("----Take---");
var t=arr.Take(3);
foreach(var s in t)
{
Console.WriteLine(s);
}
}
}

Comments or Responses

Login to post response