I have a List<A>, where A contains a property called TypeId, and a List<B>, where B also contains a property called TypeId
I want to select all items from List<A> where List<B> contains an item where B.TypeId == A.TypeId
ListA.Add(new A { TypeId = 1 });
ListA.Add(new A { TypeId = 2 });
ListA.Add(new A { TypeId = 3 });
ListB.Add(new B { TypeId = 3 });
ListB.Add(new B { TypeId = 4 });
ListB.Add(new B { TypeId = 1 });
???? // Should return items 1 and 3 only
What is the most efficient way of doing this?
I know its something simple, but my brain is feeling stupid today….
Using LINQ, it’s rather simple using the Join method.