30% OFF - 10th Anniversary discount on new purchases until December 15 with code: ZZZANNIVERSARY10
C# Eval Expression LINQ Dynamic - ElementAt
LINQ Dynamic ElementAt Examples
C# Dynamic LINQ ElementAt examples using an Expression Evaluator.
ElementAt
This C# example uses the LINQ ElementAt method with a dynamic expression to retrieve the second number greater than 5 from an array.
LINQ
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; var fourthLowNum = numbers.Where(n => n > 5).ElementAt(1); // second number is index 1 because sequences use 0-based indexing Console.WriteLine("Second number > 5: {0}", fourthLowNum);
LINQ Execute
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}; var fourthLowNum = numbers.Where(n => n > 5).Execute<int>("ElementAt(1)"); // second number is index 1 because sequences use 0-based indexing Console.WriteLine("Second number > 5: {0}", fourthLowNum);
Result
Second number > 5: 8