Where method (with objects)

Description

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

Sample

This sample filters a list of Person objects by the Age property. Only Persons with the Age >= 30 are included in the result.

var data := List<Person>{}{ ;
   Person{}{Name := "Jon Doe", Age := 40}, ;
   Person{}{Name := "Jane Doe", Age := 20}, ;
   Person{}{Name := "Joe Schmoe", Age := 30} ;
}

var result := data:Where({ q => q:Age >= 30 })

foreach var item in result 
   Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
next

Output

Jon Doe (40)
Joe Schmoe (30)

Complete sample

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

procedure Execute() as void strict

   var data := List<Person>{}{ ;
      Person{}{Name := "Jon Doe", Age := 40}, ;
      Person{}{Name := "Jane Doe", Age := 20}, ;
      Person{}{Name := "Joe Schmoe", Age := 30} ;
   }

   var result := data:Where({ q => q:Age >= 30 })

   foreach var item in result 
      Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
   next
   return

class Person
   public property Name as string auto
   public property Age as int auto
end class
var data := List<Person>{}{ ;
   Person{}{Name := "Jon Doe", Age := 40}, ;
   Person{}{Name := "Jane Doe", Age := 20}, ;
   Person{}{Name := "Joe Schmoe", Age := 30} ;
}

var result := from q in data ;
              where q:Age >= 30 ;
              select q

foreach var item in result 
   Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
next

Output

Jon Doe (40)
Joe Schmoe (30)

Complete sample

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

procedure Execute() as void strict

   var data := List<Person>{}{ ;
      Person{}{Name := "Jon Doe", Age := 40}, ;
      Person{}{Name := "Jane Doe", Age := 20}, ;
      Person{}{Name := "Joe Schmoe", Age := 30} ;
   }

   var result := from q in data ;
                 where q:Age >= 30 ;
                 select q

   foreach var item in result 
      Console.WriteLine(String.Format("{0} ({1})", item:Name, item:Age))
   next
   return

class Person
   public property Name as string auto
   public property Age as int auto
end class