Home

Aggregate Issue

edited July 2014
(new [] { "A", "B", "C" }) .Aggregate( "Initial", (accumulated,current) => string.Format( "{0}+{1}", accumulated, current ) )

That gives "Initial+A+B+C" on some machines and "Initial" on others. I believe the former is correct. Differences in environment include the installation of Visual Studio 2013 and use of a Premium license on the machines returning "Initial". When using .Dump() within the lambda, it appears to be called with the seed and each element instead of the accumulated value and each element.

The difference disappears if the + operator is used instead. The difference disappears for the overload with fewer arguments. The difference persists for the overload with more arguments. The difference persists for some other, more complicated values of source and func, including some without strings involved at all.

I am aware that's a dumb way to do the operation in question. The original incidence involved a NuGet package, nested IList<T>s, and a more complicated lambda with another call to Aggregate(). This is simply a closer-to-minimal example.

Edit: I broke the line awkwardly to avoid the forced line break in an even worse position.
Sign In or Register to comment.