前回「n回処理を繰り返したい (1)」の続きです。 こういった繰り返し処理の時には、何回目の処理かを知りたい場合があります。 そんな時のために、もう一つ拡張メソッドを用意しましょう。 public static class IntExtentions { ... public static void Times(this int value, Action<int> action) { for (int i = 0; i < value; i++) action(i); } } こすれば、次のようなコードが可能になります。 var nums = new int[10]; 10.Times(n => nums[n] = n + 1); 参考に、for文使ったコードも示します。 var nums = new int[10]; for (int n = 0; n < 10; n++) nums[