Created
August 29, 2012 14:04
-
-
Save rohinomiya/3513028 to your computer and use it in GitHub Desktop.
指定回数処理を繰り返すメソッド(拡張メソッド) ref: http://qiita.com/items/cded0dba429581655db2
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
namespace Rohinomiya | |
{ | |
/// <summary> | |
/// intクラスを拡張する | |
/// </summary> | |
public static class IntExtensions | |
{ | |
/// <summary> | |
/// [count] 回 処理を繰り返す | |
/// | |
/// 使用例: 3.Times( i => Console.WriteLine(i.ToString())); | |
/// </summary> | |
/// <param name="count">繰り返す回数</param> | |
/// <param name="action">実行させたいActionデリゲート</param> | |
public static void Times(this int count, Action<int> action) | |
{ | |
for (int i = 1; i <= count; i++) | |
action(i); | |
} | |
} | |
} |
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
3.Times( i => Console.WriteLine(i.ToString())); |
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
1 | |
2 | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment