I’m inspired after having watched doug talk about javascript this morning, to extend C#.

Well, how about a repeat keyword?

I’d like this to have easy syntax like:

repeat: 50
print(‘hi’);

Instead of having to use a for loop as a repetition mechanism. Here’s how it’d work:

using System;

public delegate void Repeat( Action func, int numTimes ) ;

class Program
{
  static Repeat repeat = delegate( Action f, int n )
  {
    for( int i = 0; i < n; i++ )
    {
      f();
    }
  };

  static void Main( string[] args )
  {
    repeat(

      delegate()
      {
        Console.Write( "hi " );
      },

      5 );

  }
}

Post a Comment