Count method (with objects)

Description

The Count method returns the number of elements in sequence that meet the specified condition.

Sample

This sample returns the number of elements in a list with a quantity greater then 4.

var data := List<OrderItem>{}{ ;
   OrderItem{}{ArticleCode := "Apple", Quantity := 10, Price := 1.5m}, ;
   OrderItem{}{ArticleCode := "Banana", Quantity := 2, Price := 2m}, ;
   OrderItem{}{ArticleCode := "Apple", Quantity := 5, Price := 1.5m} ;
}

var result := data:Count({ q => q:Quantity > 4 })

Console.WriteLine(result)

Output

2

Complete sample

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

procedure Execute() as void strict

   var data := List<OrderItem>{}{ ;
      OrderItem{}{ArticleCode := "Apple", Quantity := 10, Price := 1.5m}, ;
      OrderItem{}{ArticleCode := "Banana", Quantity := 2, Price := 2m}, ;
      OrderItem{}{ArticleCode := "Apple", Quantity := 5, Price := 1.5m} ;
   }

   var result := data:Count({ q => q:Quantity > 4 })

   Console.WriteLine(result)
   return

class OrderItem
   public property ArticleCode as string auto
   public property Quantity as int auto
   public property Price as decimal auto
end class