tags:

views:

295

answers:

1

Hey there.

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 that i do not want to use "Foreach" to reach my goal)

Thanks for the time.

+3  A: 
List<MyObjectType> myObjectList = GetObjectValues();

List<ValueType> valueList = GetValues();

List<MyObjectType> filterdObjectList =
             myObjectList.Where(x => valueList.Contains (x.objectProp))
Developer Art
The `Contains` call will have much better performance if you use a `HashSet<T>` for `valueList` instead of a `List<T>`.
LukeH
10x a lot! It works.:D
TestSubject09
Pay attention to the Luke's advice if you have lots of values to match against.
Developer Art
ok,..I will, thanks again.
TestSubject09