Requirement: In an unsorted List, determine if a duplicate exists.
The typical way I would do this is an n-squared nested loop. I’m wondering how others solve this. Is there an elegant, high performance method in Linq? Something generic that takes a lambda or a comparer would be nice.
Note: This is different than LINQ find duplicates in List which returns the actual duplicates. I just need to know if one exists or not.
Unless I’m missing something, then you should be able to get away with something simple using
Distinct(). Granted it won’t be the most complex implementation you could come up with, but it will tell you if any duplicates get removed: