Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top