Get the first four element in the list : Take « LINQ « C# / CSharp Tutorial






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

    class Program
    {
        static void Main(string[] args)
        {

            int[] integers = { 1, 6, 2, 27, 10 };
            

            IEnumerable<int> firstFourNumbers = integers.Take(4);
            Console.WriteLine("First 4 numbers:");
            foreach (var num in firstFourNumbers)
            {
              Console.WriteLine(num);
            }

        }
    }








22.71.Take
22.71.1.Take operator outputs the first x elements, discarding the rest
22.71.2.Use Take
22.71.3.Take method
22.71.4.Take and SelectMany
22.71.5.Partitioning Operators: uses Take to generate a sequence of the first three elements of an integer array.
22.71.6.Nested Take
22.71.7.Get the first four element in the list