Created
March 30, 2014 02:50
-
-
Save baba-s/9866655 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| /// <summary> | |
| /// IEnumerable 型の拡張メソッドを監理するクラス | |
| /// </summary> | |
| public static partial class IEnumerableExtensions | |
| { | |
| /// <summary> | |
| /// IEnumerable の各要素に対して、指定された処理を実行します。 | |
| /// </summary> | |
| /// <typeparam name="T">IEnumerable の型</typeparam> | |
| /// <param name="source">IEnumerable のインスタンス</param> | |
| /// <param name="action">IEnumerable の各要素に対して実行する Action デリゲート</param> | |
| public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) | |
| { | |
| foreach (var n in source) | |
| { | |
| action(n); | |
| } | |
| } | |
| /// <summary> | |
| /// IEnumerable の各要素に対して、指定された処理を実行します。 | |
| /// </summary> | |
| /// <typeparam name="T">IEnumerable の型</typeparam> | |
| /// <param name="source">IEnumerable のインスタンス</param> | |
| /// <param name="action">IEnumerable の各要素に対して実行する Action デリゲート</param> | |
| public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> action) | |
| { | |
| foreach (var n in source.Select((val, index) => new { val, index })) | |
| { | |
| action(n.val, n.index); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment