LINQ-USE TAKE TO GET FIRST 3 ELEMENTS OF THE ARRAY

With the use of following function you can get first 3 elements of the array

          public void TakeExample()
        {

            int[] numbers = { 4, 23, 4, 5, 7, 8, 9, 12, 23, 45 };

            var Numbers = numbers.Take(3);

            Console.WriteLine("First 3 numbers:");

            foreach (var n in Numbers)
            {

                Console.WriteLine(n);


            }
        }

Ebook Download
View all
Learn
View all