Get values greater than 4 from the array - CSharp LINQ

CSharp examples for LINQ:Query Array

Description

Get values greater than 4 from the array

Demo Code



using System;/*from  w w  w.ja v a  2s .c om*/
using System.Linq;

class MainClass
{
   static void Main()
   {
      var values = new[] {2, 19, 5, 0, 3, 7,11, 4, 18, 5};

      foreach (var element in values)
      {
         Console.Write($" {element}");
      }

      // LINQ query that obtains values greater than 4 from the array
      var filtered =
         from value in values // data source is values
         where value > 4
         select value;

      // display filtered results
      Console.Write("\nArray values greater than 4:");
      foreach (var element in filtered)
      {
         Console.Write($" {element}");
      }
   }
}

Result


Related Tutorials