Say I've got two lists:
List<string>foo=new List<string>();
List<string>bar=new List<string>();
I want to merge these two lists and return another list with only the duplicates in the both.
So if I have:
//pseudocode
foo={"baz","lemons","somethingelse"}
bar={"what","another","baz","somethingelse","kitten"}
I want it to return a new List:
//pseudocode
dupes={"baz","somethingelse"}
I think using LINQ will be the best shot. However, I haven't quite figured that since I have poor LINQ experience.
Intersect
is what you want which is part of LINQ.
dupes = foo.Intersect(bar).ToList();
Ensure you have the System.Linq
namespace referenced in your file.
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