The method ForEach()
has no relation to the Entity Framework.
He’s a class method List
, see documentation. Note that he has no relation to LINQ, he is a native of List
.
There is no important difference between the two. They are two different ways of doing the same thing. Basically the method uses the for to go through all the elements.
Here is the method code:
public void ForEach(Action<T> action) {
if( action == null) {
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
Contract.EndContractBlock();
int version = _version;
for(int i = 0 ; i < _size; i++) {
if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) {
break;
}
action(_items[i]);
}
if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
}
See more in referencesource.microsfot.com
Obviously it changes the way the code is written/read a lot, which is better or more readable is a matter of taste.
I find it interesting to read this article by Eric Lippert that deals with the subject (not directly from your question, but treats).
The RU is Linq, the bottom is not
– Artur Trapp
More and the performance ?
– Matheus Miranda