Sunday, September 21, 2008

Weekly Code: Predicates In C++/CLI (21/09/2008)

In C++/CLI every .Net generic List collection (List class) which is in the System.Collections.Generic namespace have methods like FindAll that takes in a Predicate as a parameter.

A Predicate is a delegate that to a method that return true if a match is find in the collection base on a condition in the delegate method. It make it easy to find a element match in a collection without writting a complicated for each loop for example.

C# make this easy by using anonymous methods in C# 2.0 and lamda expressions in C# 3.0 but C++ language doesn't have this feature (C++/CLI is base on C++ that doesn't have anonymous methods/lamda expressions)

In this example I demostrate using predicates in C++/CLI with Visual C++.Net 2008 to find items in a collection.

If your interested in C++/CLI then I suggest reading C++/CLI In Action.

Weekly Code List

No comments: