I have 2 different classes:
public class ClassOne
{
public string ClassOneID { get; set; }
...
}
public class ClassTwo
{
public string ClassTwoID { get; set; }
...
}
I have IEnumerable
instances of each. I want to return a List<ClassOne>
that contains only the ClassOne
items whose ClassOneID
is equal to the ClassTwoID
of a ClassTwo
object from the second IEnumerable
instance (if that makes sense!). I was thinking the following:
var list = new List<ClassOne>();
list.AddRange(classOneEnumerable.Where(o =>
classTwoEnumerable.Select(c => c.ClassTwoID == o.ClassOneID).First()));
This logic is contained within code that is some days off building/testing, so I am not actually able to run it just yet. I am not sure if what I have come up with is actually correct, and was hoping someone could put me right if I am mistaken.