Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

What's the syntax for searching a generic collection with more than 1 condition?

Hi,
I need to search and see if there is a match in my generic collection with 4 constraints.  
myColleciton.Find(x => x.Name == users.GivenName);

How do I add on match requirements for last name, middle name...?
Thank you.
Avatar of plusone3055
plusone3055
Flag of United States of America image

myColleciton.Find("john","a","smith","whatever4thConstrinatismatch");
Avatar of lapucca
lapucca

ASKER

I don't have to use that predicate syntax crap like x=>x......
?
not if you don't want to.

your constraintsahoul be in the colletion so either use strings (if you have strings that have the values you need)
or just use double quotes for the values you wan to match)
Avatar of lapucca

ASKER

Go error when I put in just my 4 constraints, mouse over to see the error message.  Error says "No overload method for Find that takes 4 arguments.
for example if you were looking for metadata in a colletion like a keyword

C.KeywordTypes.Find("Account #")
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S.

Just keep in mind that the stuff on the left side of the arrow ( => ) is the variable declarations (with types optionally specified), and the stuff on the right is what will actually be executing.
Avatar of lapucca

ASKER

I tried both with and without parentheses and both got me the same red underline error message.

                        users.Find(x => x.GivenName == gridEditUser.GivenName && x.Surname == gridEditUser.Surname && x.MiddleName == gridEditUser.MiddleName && x.VoiceTelephoneNumber = gridEditUser.VoiceTelephoneNumber);

                        users.Find(x => (x.GivenName == gridEditUser.GivenName) && (x.Surname == gridEditUser.Surname) && (x.MiddleName == gridEditUser.MiddleName) && (x.VoiceTelephoneNumber = gridEditUser.VoiceTelephoneNumber));

I'm using VS2012.  According to this link, http://stackoverflow.com/questions/12406750/find-item-in-generic-list-by-specifying-multiple-condition, it should work with either.  Can you see what's wrong with my code?  Thank you.
Avatar of lapucca

ASKER

Found my typo, I'm missing a "=" at the last constraint.  Should be "==".  

Thank you.