From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Create custom aggregates

Create custom aggregates

- [Instructor] Blank provides us the aggregate function so that we can create our own custom operation for the aggregate. Start by running the query to see what our data source is. So look at this grid here, I've got three, six, nine, 12, 15, and 18. They're all stored in an IEnumerable of INT 32. And that's being generated here on line three. Next, I go to line six, and I call aggregate, and I have to pass in a delegate of the operation that I want to to perform. Now because we need two arguments, I need to use syntax like this. This is a Lambda, but I need to provide two parameters. So I use an open and close set of parentheses, and I call it my first argument first, and my second, second. Another naming convention you see often is A comma B. What's my operation? Take the first value and multiply by the second value, and that results and this value right here, 524,880. You also can provide what's called a seed. So if…

Contents