First method (objects with condition)

Description

The First method with condition returns the first element of the sequence that satisfies a condition or a default value if no such element is found.

Sample

This sample gets the first Person, where the Age gerater then 30.

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:First({ q => q:Age > 30 })

Console.WriteLine(String.Format("{0} ({1})", result:Name, result:Age))

Output

Jon Doe (40)

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:First({ q => q:Age > 30 })

   Console.WriteLine(String.Format("{0} ({1})", result:Name, result:Age))
   return

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