The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Next generation iteration: Array.ForEach and Delegate inference

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Next generation iteration: Array.ForEach and Delegate inference Posted: Dec 31, 2004 1:33 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Next generation iteration: Array.ForEach and Delegate inference
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement

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[]{..};

Array.ForEach(MyArray,MyFunction);

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.

Read: Next generation iteration: Array.ForEach and Delegate inference

Topic: Looking for a good, cheap ASP.NET host/provider Previous Topic   Next Topic Topic: Juval Lowy on TDD

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use