LINQ: "contains" and a Lambda query

mark smith picture mark smith · Oct 14, 2009 · Viewed 247k times · Source

I have a List<BuildingStatus> called buildingStatus. I'd like to check whether it contains a status whose char code (returned by GetCharCode()) equals some variable, v.Status.

Is there some way of doing this, along the lines of the (non-compiling) code below?

buildingStatus.Contains(item => item.GetCharValue() == v.Status)

Answer

Rex M picture Rex M · Oct 14, 2009

Use Any() instead of Contains():

buildingStatus.Any(item => item.GetCharValue() == v.Status)