Follow @RoyOsherove on Twitter

Next generation iteration: Array.ForEach and Delegate inference

Sriram goes through hoops trying to write a function that maps a list to a function pointer that will be called on each item of the list. Yeah, it's easier in Smalltalk, today. But here's how it looks in .Net 2.0:

Person[] MyArray = new Person[]{..};


private void MyFunction(Person p)


//do something



How "Perl"ish :)

A few new things here:

  1. A whole bunch of new methods has been added to the BCL with support for automatic iterations such as Array.ForEach()
  2. You don't have to create a delegate just to point at a specific function. The compiler "resolves" this for you and infers the correct delegate type to create form the function you point to.
  3. The function just needs to match the loop variable.

Very cool.

Is PostXing gonna solve my blogging needs?

Comparing C++ unit testing frameworks