Skip to content

Instantly share code, notes, and snippets.

@rohinomiya
Created August 29, 2012 14:04
Show Gist options
  • Save rohinomiya/3513028 to your computer and use it in GitHub Desktop.
Save rohinomiya/3513028 to your computer and use it in GitHub Desktop.
指定回数処理を繰り返すメソッド(拡張メソッド) ref: http://qiita.com/items/cded0dba429581655db2
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);
}
}
}
3.Times( i => Console.WriteLine(i.ToString()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment