First, let me specify I am refering to the List<T>
method and not the C# keyword. What would be Microsoft's reasoning for having the Foreach method on the List<T>
collection but no other collection/enumerable type, specifically IEnumerable<T>
?
I just discovered this method the other day, and found it to be very nice syntax for replacing traditional foreach loops that only perform one or 2 lines of methods on each object.
It seems like it would be fairly trivial to create an extension method that ,performs this same function. I guess I'm looking at why MS made this decision and based on that if I should just make an extension method.