Reputation: 705
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
Upvotes: 0
Views: 79
Reputation: 2185
Try this:
List<AClass> results = lst.Where( x => x.aRole!= null && conditions.Contains(x.aRole.Value)).ToList();
Upvotes: 1