Take method : Take « LINQ « C# / C Sharp






Take method

 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"A", "A", "B", "Bu", "Car", "land"};

        IEnumerable<string> items = presidents.Take(5);

        foreach (string item in items)
            Console.WriteLine(item);
    }
}

 








Related examples in the same category

1.Take operator outputs the first x elements, discarding the rest
2.Use Take
3.Take and SelectMany
4.Partitioning Operators: uses Take to generate a sequence of the first three elements of an integer array.
5.Nested Take