I’m using .Aggregate on a List<String> to concatenate each item. I need to find out when the iteration has hit the last item. I was considering testing listOfStrings.Last() == currentString but the last item in the list could equal any other if the value is the same.
I’m using .Aggregate on a List<String> to concatenate each item. I need to find
Share
Why do you need to know this?
I’m just guessing, but it sounds like you’re doing something similar to generating a string such as “x, y, z” and you don’t want a comma after the last item.
If this is the case, you can use
string.Join(separator, items)instead. Unless you want something which fits the form of “x, y & z”?If you really need to use
Aggregate, you can close over an external variable, like: