When I run this code:
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
list.Add("c");
list.Add("d");
string s = list.Aggregate((total, item) => total += item + ",");
I expect s to be:
a,b,c,d,
but instead, s is:
ab,c,d,
can anyone tell me why it’s not appending a comma between the first and second index?
Thanks
You will find that this works
You can see why if you test this:
This results in “ab,”
Using an initial empty seed value for total (either (string)null or string.Empty) will give you the expected result.