Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created February 24, 2018 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/6dfb6a38bc0faaa74f0f29c3cb09570e to your computer and use it in GitHub Desktop.
Save dance2die/6dfb6a38bc0faaa74f0f29c3cb09570e to your computer and use it in GitHub Desktop.
private static void AggregateDemo(List<Order> orders)
{
const int initialQuantity = 0;
var totalQuantities = orders.Aggregate(initialQuantity, (sum, order) => sum + order.Quantity);
// Same as Order simply use a convinient `Sum()` method.
// var totalQuantities = orders.Sum(order => order.Quantity);
System.Console.WriteLine($"Total Quantities: {totalQuantities}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment