public void TakeSimple()
{
int[] num = { 34,56,72,74,223,442,4, 61 , 40 };
Console.WriteLine("Print num ");
foreach (int j in num)
Console.Write("{0} ",j);
Console.WriteLine("\n\nPrint num with take(5) ");
IEnumerable
foreach (int j in i)
{
Console.Write("{0} ",j);
}
}
OUTPUT :
Print num
34 56 72 74 223 442 4 61 40
Print num with take(5)
34 56 72 74 223
Example Nested : Following example first check a condition using restriction operator 'where', then applies 'Take' to the result
public void TakeNested()
{
int[] num = { 34, 36 , 56, 72, 45 , 74, 223, 442, 4, 61, 40 };
Console.WriteLine("Print num");
foreach (int j in num)
Console.Write("{0} ", j);
Console.WriteLine("\n\nPrint num where value > 25");
IEnumerable
foreach (int j in i1)
Console.Write("{0} ", j);
Console.WriteLine("\n\nPrint num where value > 25 and take only 5");
IEnumerable
foreach (int j in i2)
Console.Write("{0} ", j);
}
OUTPUT :
Print num
34 36 56 72 45 74 223 442 4 61 40
Print num where value > 25
34 36 56 72 45 74 223 442 61 40
Print num where value > 25 and take only 5
34 36 56 72 45