More New Content

Latest online articles:

Wasting Energy, and Rotating Things (Code Magazine, Sep/Oct 2006)

In which one finally learns how the home theater turned out, why the air-conditioning bills are too high, and a better way to rotate objects in .NET (without using trigonometry). More...

Advanced Basics -- Predicates and Actions (MSDN Magazine, September 2006)

It's not that I'm lazy, but it really bothers me to have to manually iterate through all the members of a collection, taking an action on each. I wish I could just tell the collection what to do for each member and let it do the iterating. Well, guess what? On a recent exploration of the Microsoft® .NET Framework, I found just the solution to this and other nagging array and list issues. It turns out that the System.Array and System.Collections.Generic.List classes of the .NET Framework 2.0 each provide a number of methods, such as Find, FindAll, and FindLast, that let you avoid writing code to loop through every element of an array or list to find the one or more items you're looking for. You get the ability to "walk" an entire data structure, determining whether each item meets a set of criteria, without having to write the boilerplate code to loop through each row manually. In addition, because the predicate—the focus of this column— is simply the address of a procedure to call that, in effect, says yea or nay on each item in the collection, you can easily change the search criteria at run time. More...

Published Saturday, September 02, 2006 2:52 PM by KenG

Comments

No Comments