❔ Write an Aggregate
Could I aggregate through
Input
to archive the same result? I'm learning the linq Aggregate
, and just curious if I could archive the same result with an Aggregate
?5 Replies
Yes, you could use the Aggregate method to achieve the same result as the code you posted. The Aggregate method allows you to perform a calculation on a sequence and return a single result. In this case, you could use it to track the visited houses and return the total number of houses visited.
Here's an example of how you could use Aggregate to accomplish this:
As you can see, the Aggregate method allows us to perform the same operations as the code you posted, but with a more concise and functional-style syntax. I hope this helps! Let me know if you have any other questions.
Can I have multiple parameters here
(houses, direction)
or is it set?
The solution looks wonderful, thanks by the way.It's always two params. The accumulation thing, and the next element
I see, that's good to know. Thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.