ExtensionMethod.NET Home of 820 C#, Visual Basic, F# and Javascript extension methods

Times

Repeats an action a number of times.

Source

public static void Times(this int repeatCount, Action<int> action) {
  for (int i = 1; i <= repeatCount; i++) {
    action(i);
  }
}

Example

DataTable table = GetSomeTable();
var noOfRows = table.Rows.Count;
noOfRows.Times(rowNo => {
  var row = table.Rows[rowNo];
  Console.WriteLine("rowNo:{0}, Name:{1}", rowNo, row["Name"]);
});

Author: Richard Bushnell

Submitted on: 3 mrt 2008

Language: C#

Type: System.Int32

Views: 3147