How many times do you enumerate your collections to perform some operations? How many times do you use following idiom?
Isn't it boring?
It seems that the List<T> has a rather rarely used method, ForEach which can be used instead of C#'s foreach:
This looks especially refreshing when used for loops that initialize containers. Compare the usual version:
with the new one:
Note that the for instruction is missing and instead Enumerable.Range with ForEach is used to get the same result.
One could surely argue if this new version is more readable but compare this one:
and this one:
Yet another interesting but rarely used pattern arises when literal representations of list items must be merged together to form a literal representation of the list. I often see something like that:
while string.Join should be used to get the same result with much cleaner code: