I'm trying to find duplicates in an array and put only the duplicates in an array. The code im using is the following
Dim duplicates As List(Of String) =
WithDuplicates.GroupBy(Function(n) n) _
.Where(Function(g) g.Count() > 1) _
.Select(Function(g) g.First) _
.ToList()
Dim DuplicatesOnly As String() = duplicates.ToArray
WithDuplicates is the Array that contains the duplicates. Before, I used a richtextbox instead of a array but I had to switch to an array because of threading. I don't know why my code isnt working anymore. Any ideas how I could get this working?
Edit: The code above does indeed work, another part of my code caused the error.
StringComparer.InvariantCultureIgnoreCase(orStringComparer.CurrentCultureIgnoreCase) to the grouping?DuplicatesOnlythat is different from what you expected? Something else? -- What has Threading to do with this?DuplicatesOnlyis empty because no duplicates were found orWithDuplicatesis empty -- When you post your code, you always need to give it context. You also need to debug your code: put a breakpoint in the first line, inspect the variables / values and step in one line at the time. Get rid of any MessageBox, print to the Output Window, when needed, instead (Console.WriteLine()orDebug.WriteLine()) -- What is the content ofWithDuplicatesand where does it come from? How is threading involved? Update your questions with this information.