Closed oliverbooth closed 2 years ago
Type
System.IEnumerable<T>
Extension method signature
void For<T>(System.Action<int, T>); // and void ForEach<T>(System.Action<T>);
For
System.Action<int, T>
Action<int, T>
IEnumerable<T>
int
ForEach
System.Action<T>
Action<T>
Description Performs the specified action on each element of the IEnumerable<T>.
Benefits Similar functionality exists built-in for List<T>, see https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.foreach?view=net-6.0 - this functionality is not provided for IEnumerable<T>
List<T>
Drawbacks Potential naming collisions when attempting to call on a List<T>
(Optional) Implementation example
{ foreach (T item in source) { action(item); } }
Type
Extension method signature
For
System.Action<int, T>
Action<int, T>
delegate to perform on each element of theIEnumerable<T>
. Theint
argument passed to this delegate represents the index.ForEach
System.Action<T>
Action<T>
delegate to perform on each element of the `IEnumerableDescription Performs the specified action on each element of the
IEnumerable<T>
.Benefits Similar functionality exists built-in for
List<T>
, see https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.foreach?view=net-6.0 - this functionality is not provided forIEnumerable<T>
Drawbacks Potential naming collisions when attempting to call on a
List<T>
(Optional) Implementation example