Created
August 29, 2012 15:25
-
-
Save rohinomiya/3514320 to your computer and use it in GitHub Desktop.
ForEach()メソッドをシンプルに書けるようにする ref: http://qiita.com/items/99aa993cfe5def51bbe5
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; | |
namespace Rohinomiya | |
{ | |
/// <summary> | |
/// Arrayクラスを拡張する | |
/// </summary> | |
public static class ArrayExtension | |
{ | |
/// <summary> | |
/// ForEachメソッド | |
/// </summary> | |
/// <param name="array">Arrayクラス</param> | |
/// <param name="action">実行させたいActionデリゲート</param> | |
public static void ForEach<T>(this T[] array, Action<T> action) | |
{ | |
Array.ForEach<T>(array, obj => action(obj)); | |
} | |
} | |
} |
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 Rohinomiya; | |
namespace SampleForEach | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var dirs = new string[]{"aa","bb","cc"}; | |
Array.ForEach<string>(dirs, s => Console.WriteLine(s) ); // a | |
dirs.ForEach(s => Console.WriteLine(s)); // b:こういう書き方したい | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment