Sum method (with objects)
Description
The Sum method calculates the total for a numeric sequence.
Sample
This sample calculates the sum of values for a list of objects.
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:Sum({ q => q:Quantity * q:Price })
Console.WriteLine(result)
Output
26,5
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:Sum({ q => q:Quantity * q:Price })
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