I'm trying to search a list and see if an ID is in it.
string idText = item["FCSID"].Text;
var sfhOptions = PathologySFHByRole.GetSFHOptionsByRoles(Model.pathologyFishCultureStation);
if (!sfhOptions.Contains(x => x.ID == int.Parse(idText)))
e.Item.Cells[0].Visible = false;
The GetSFHOptionsByRoles returns an IList. My lambda expression gets the error: Cannot convert the lambda expression to type SFHType because it is not a delegate type
What's the best practice for this?
You can use Any
:
int id = int.Parse(idText);
e.Item.Cells[0].Visible = sfhOptions.Any(x => x.ID == id);
IList<T>.Contains
expects an object of type SFHType
instead of a predicate.