Where method (with integers)

Description

The Where method filters a sequence of values based on a predicate.

Sample

This sample filters a list of integers. Only values greather then 1 and less then 5 are included in the result.

var data := List<int>{} { 5, 3, 1, 2, 4 }

var result := data:Where({ q => q > 1 .and. q < 5 })

foreach var item in result 
   Console.WriteLine(item)
next

Output

3
2
4

Complete sample

using System
using System.Linq
using System.Collections.Generic

procedure Execute() as void strict

   var data := List<int>{} { 5, 3, 1, 2, 4 }

   var result := data:Where({ q => q > 1 .and. q < 5 })

   foreach var item in result 
      Console.WriteLine(item)
   next
   return

var data := List<int>{} { 5, 3, 1, 2, 4 }

var result := from q in data ;
              where q > 1 .and. q < 5 ;
              select q

foreach var item in result 
   Console.WriteLine(item)
next

Output

3
2
4

Complete sample

using System
using System.Linq
using System.Collections.Generic

procedure Execute() as void strict

   var data := List<int>{} { 5, 3, 1, 2, 4 }

   var result := from q in data ;
                 where q > 1 .and. q < 5 ;
                 select q

   foreach var item in result 
      Console.WriteLine(item)
   next
   return