Created
November 21, 2015 12:48
-
-
Save TangChr/f41e3e42fe8b9482cf27 to your computer and use it in GitHub Desktop.
C#: Add condition to Extension Method .ForEach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace TangChr | |
{ | |
public static class ExtendForEach | |
{ | |
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action, Func<T, bool> condition) | |
{ | |
for (int i = 0; i < collection.Count(); i++) | |
{ | |
if (condition(collection.ElementAt(i))) | |
action(collection.ElementAt(i)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment