There is a long and tedious way I could perform the task I want to accomplish, but I am thinking there must be a way using Linq or some other neater more efficient technique to achieve this. I have a IEnumberable lets call it people1 with properties firstName and lastName, I also have a List lets call it people2 also with firstName and lastName properties. I need to store only the people1 where the firstName and lastName values of people2 match that of people1.
This pseudo code doesn't work but it might explain better what I hope to achieve than that wordy explanation:
people3 = people1.Select(x => x.firstName IN (people2.firstName) && x.lastName IN (people2.lastName))
I am kinda new to this so the only way I came up with of doing it was looping through the people2 list elements comparing people1 and if it matches storing it in people3. This will work but I am assuming there is a nicer way to do it and I am trying to learn new things so I thought I would throw this out there to see what your great minds come up with. :)
UPDATE:
After playing around a bit I am close but can't seem to figure out how to add the matching items to a new IEnumerable object. Here is the code I have, it fails on the "Add" line:
IEnumerable<dynamic> people3 = null;
foreach(var person in people1)
{
if(people2.Exists(x => x.FirstName == people1.FirstName))
{
people3.Add(person);
}
}