0

I was hoping to do something like:

int[] locations;

do
{/*edit locations to only contain one int in array of same value*/}
while (locations.Where(val, secondVal => val == secondVal).count > 1)

And I highly feel like I've done something of the sort in the past, perhaps it was with a list and it doesn't function the same way with an array but I can't seem to find my example anywhere.

I feel that the code snip explains well enough my intentions, but it doesn't work, would someone be able to help? Thanks.

I'll keep searching online but if someone could help it would obviously speed up my search.

Alox
  • 651
  • 12
  • 24
  • So to clarify, you want your result set to be effectively all numbers who exist twice in your starting set? Ideally please provide sample input and output. – JBC Feb 24 '17 at 18:27
  • Is the array sorted, and/or are we allowed to sort it? – hoodaticus Feb 24 '17 at 18:27
  • yeah, it's to go on while there are two values inside the locations array that are similar, but it seems that Juan Bayona answered my question, I had just forgotten how to do it. Thanks for your help! – Alox Feb 24 '17 at 18:30

1 Answers1

2

You should look to this answer: C# LINQ find duplicates in List

Just group elements by its value and then get the list

GroupBy(x=>x).Where(g=>g.Count()>1)
Community
  • 1
  • 1
  • thank you, since this is a duplicate I'll delete it, I simply didn't remember how to do this and couldn't find it. Can't delete because theres an answer, I'll accept this once the minimum wait has passed. – Alox Feb 24 '17 at 18:29