The following code results in C3867 (...function call missing argument list...) and C3350 (...a delegate constructor expects 2 argument(s)...). What am I doing wrong?
public ref class Form1 : public System::Windows::Forms::Form
{
public:
bool IsEven(int i){
return (i % 2) == 0;
}
Form1(void)
{
numbers = gcnew array<int>{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
array<int> ^even = Array::FindAll(
numbers, gcnew Predicate<int>(IsEven));
}
};
In C++/CLI you have to pass the actual instance of the type containing the function:
(or make your
IsEven
methodstatic
)The following simple console application provides examples of the
FindAll()
method with anarray
in .NET C++/CLI.This works with Visual Studio 2005 which does not provide support for lambdas. Since your example is using Windows Forms, I provide an extra class in this Windows console application to show the
Predicate
function from a class when used in theFindAll()
.This example shows three different mechanisms for providing a predicate:
This is a very basic sample using
int
however it does also work with more complex data structures as well.The output from this program looks like the following: