Reputation: 411
I'm searching for a way to auto compare an object propriety to a list of values inside a lambda expression. For example I have this lambda expression:
List<MyObjectType> myObjectList = GetObjectValues();
List<MyObjectType> filterdObjectList = myObjectList.Where(x => x.objectProp == ??a list of values??)
Basicly I need to filter my list of objects after the "objectProp"
that can have multiple valid values.(Note: I do not want to use "Foreach"
)
Upvotes: 4
Views: 10296
Reputation:
List<MyObjectType> myObjectList = GetObjectValues();
List<ValueType> valueList = GetValues();
List<MyObjectType> filterdObjectList =
myObjectList.Where(x => valueList.Contains (x.objectProp))
Upvotes: 7