Reputation: 6547
I am currently making an application where I need to check if 2 or more items in an array are the same.
Here is what I have so far:
Dim aNumbers = New Short() {iNumOne, iNumTwo, iNumThree}
How would I check if 2 or more variables are the same in the array?
Thanks
Upvotes: 0
Views: 204
Reputation: 11773
This will tell you if there are duplicates present
Dim dups As Boolean = Not aNumbers.Distinct.Count.Equals(aNumbers.Length)
If dups Then
'there are duplicates
Else
'no duplicates
End If
Upvotes: 1
Reputation: 332
Maybe something like this
Using LINQ
Dim aNumbers_filtered = From number In aNumbers _
Group number By Key = number Into Group _
Where Group.Count() > 1
Select Number = Key, NumberCount = Group.Count()
Upvotes: 0