Im having two List items, how can I write a linq query to compare both and extract the common items.(Like List c, as shown below)
List<string> a = {a, b, c, d}
List<string> b = {c, d, e, f}
List<string> c = {c, d}
Use the LINQ Intersect method.
var commonItems = a.Intersect(b);
variable commonItems will be a collection of common items from list a and list b , which is ["c","d"]
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