I found one way to do it, but I'm not very happy with the Find() method because it only passes one parameter to the comparison function (called a Predicate). If you want to find a specific cat I don't know how to do it without using some sort of global variable that contains the cat name. CLI/C++ does not permit String^ to be global. So the Find() method is not very useful in this case.
bool FindCat(MyCat::Cat^ c)
{
return true;
}
int main(array<System::String ^> ^args)
{
List<MyCat::Cat^>^ catList = gcnew List<MyCat::Cat^>;
catList->Add(gcnew MyCat::Cat("one"));
catList->Add(gcnew MyCat::Cat("two"));
catList->Add(gcnew MyCat::Cat("three"));
String^ catname = "two";
MyCat::Cat^ myLocatedCat = catList->Find(
gcnew Predicate<MyCat::Cat^>(FindCat)
);
Console::WriteLine(L"Hello World");
return 0;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343