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.
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.
myColleciton.Find("john"," a","smith" ,"whatever 4thConstri natismatch ");
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)
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)
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("Accou nt #")
C.KeywordTypes.Find("Accou
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.VoiceTelephon eNumber);
users.Find(x => (x.GivenName == gridEditUser.GivenName) && (x.Surname == gridEditUser.Surname) && (x.MiddleName == gridEditUser.MiddleName) && (x.VoiceTelephoneNumber = gridEditUser.VoiceTelephon eNumber));
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.
users.Find(x => x.GivenName == gridEditUser.GivenName && x.Surname == gridEditUser.Surname && x.MiddleName == gridEditUser.MiddleName && x.VoiceTelephoneNumber = gridEditUser.VoiceTelephon
users.Find(x => (x.GivenName == gridEditUser.GivenName) && (x.Surname == gridEditUser.Surname) && (x.MiddleName == gridEditUser.MiddleName) && (x.VoiceTelephoneNumber = gridEditUser.VoiceTelephon
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.
ASKER
Found my typo, I'm missing a "=" at the last constraint. Should be "==".
Thank you.
Thank you.