I have two collections
List<CustomClass1> items1
List<CustomClass2> items2
CustomClass1 has a property KEY
CustomClass2 has a property KEY
i want to keep only those entries in items1 which have a matching key in items2. How can this be achieved through LINQ?
thanks
var res = items1.Join(items2,
item1 => item1.Key,
item2 => item2.Key,
(item1, item2) => item1);
var res = items1.Where(a=> items2.Any(c=>c.Key == a.Key));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With