I missed Integer#times from Ruby, so I implemented it in C#. It turned out to be very simple.


public static class Extensions
{
    public static void Times(this int count, Action<int> action)
    {
        for (int i = 0; i < count; i++)
        {
            action(i);
        }
    }
}

Use like this:


3.Times(n => Console.WriteLine(n));

Or just this:


3.Times(Console.WriteLine);