Question

i want to filter a list by a field within the list where the field exists within a set of values. i am trying to get filter the list where a Guid field exists in a list of guids

eg

public class AClass
{
    public string someField;
    public Guid? aRole;
}

and im looking to filter the list in a way similar to this :

List<AClass> lst = new List<AClass>();
// the list of guids i want to filter by
List<Guid> conditions = new List<Guid>();
List<AClass> results = lst.Where( x => x.aRole.Contains(conditions)).ToList();

I cant find a good example of how to do this. does anybody know?

Thanks

Was it helpful?

Solution

Try this:

List<AClass> results = lst.Where( x => x.aRole!= null && conditions.Contains(x.aRole.Value)).ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top