TestSubject09
TestSubject09

Reputation: 411

Compare to list inside lambda expressions

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

Answers (1)

user151323
user151323

Reputation:

List<MyObjectType> myObjectList = GetObjectValues();

List<ValueType> valueList = GetValues();

List<MyObjectType> filterdObjectList =
             myObjectList.Where(x => valueList.Contains (x.objectProp))

Upvotes: 7

Related Questions