The delegate is there to see whether the value that you're testing is what you're looking for. The call to Remove
looks worryingly like it's mutating the value though - that's rarely a good thing when you're looking through the list. I guess if it's a string then it's not too bad, although it may not be what you're after...
What are the types involved, and what are you looking for? Oh, and are you using C# 3 and/or .NET 3.5? That would make it easier (even C# 3 against .NET 2.0 means you could use a lambda expression instead of an anonymous method).
What's happening when you run the code at the moment? If it's just not finding anything, it may just be because you're testing for reference equality (if SelectedValue
returns object
).
Try this:
produto = products.FindAll(delegate(Mamamia cv) {
return cv.LocalPackage.Remove(1,21).Equals(cmbPackage.SelectedValue);
});
EDIT:
It sounds like you only want a single value, and if you're using .NET 3.5 it would be more idiomatic to use LINQ in the first place. I would use:
string selectedText = (string) cmbPackage.SelectedValue;
Mamamia item = products.FirstOrDefault
(cv => cv.LocalPackage.Remove(1,21) == selectedText);
if (item != null)
{
// Found it; otherwise item will be null
}