Created
May 23, 2013 07:09
-
-
Save vendettamit/5633219 to your computer and use it in GitHub Desktop.
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
/// <summary> | |
/// Custom function to perform looping operation. | |
/// </summary> | |
/// <typeparam name="T">type of ienumerable</typeparam> | |
/// <param name="list">The list.</param> | |
/// <param name="action">The action.</param> | |
/// <returns>index value</returns> | |
/// <exception cref="System.ArgumentNullException"> if the supplied action is null</exception> | |
public static int ForEach<T>(this IEnumerable<T> list, Action<int, T> action) | |
{ | |
if (action == null) | |
{ | |
throw new ArgumentNullException("action"); | |
} | |
var index = 0; | |
foreach (var elem in list) | |
{ | |
action(index++, elem); | |
} | |
return index; | |
} | |
/// <summary> | |
/// Fors the each. | |
/// </summary> | |
/// <typeparam name="T">type of ienumerable</typeparam> | |
/// <param name="enumeration">The enumeration.</param> | |
/// <param name="action">The action.</param> | |
public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action) | |
{ | |
foreach (T item in enumeration) | |
{ | |
action(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: