Use ElementAt to print the fourth number less that 5 in an integer array : ElementAt : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » ElementAt »

 

Use ElementAt to print the fourth number less that 5 in an integer array








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

public class MainClass {
    public static void Main() {
        int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

        int fourthLowNum = (
            from n in numbers
            where n < 5
            select n)
            .ElementAt(3); // 3 because sequences use 0-based indexing

        Console.WriteLine("Fourth number < 5: {0}", fourthLowNum);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» ElementAt