VbNet · Console
Imports System
Imports System.Collections.Generic
Imports System.Linq
Public Module Module1
Public Class Thing
Private _name As String = Nothing
Public Property Name As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _serviceGroup As Integer = 0
Public Property ServiceGroup As String
Get
Return _serviceGroup
End Get
Set(ByVal value As String)
_serviceGroup = value
End Set
End Property
Public Sub New(name as String, serviceGroup as String)
_name = name
_serviceGroup = serviceGroup
End Sub
End Class
Public Sub Main()
Dim unique1 as Thing = new Thing("test", 1)
Dim unique2 as Thing = new Thing("test1", 1)
Dim unique3 as Thing = new Thing("test", 2)
Dim dup1 as Thing = new Thing("test", 1)
Dim dup2 as Thing = new Thing("test", 1)
Dim things as Thing() = {
unique1,
unique2,
unique3,
dup1,
dup2
}
Dim duplicates As List(Of Thing) =
things.
GroupBy(Function(thing) New With {Key .Name = thing.Name, Key .ServiceGroup = thing.ServiceGroup }).
Where(Function(group) group.Count() > 1).
SelectMany(Function(group) group.ToList).
ToList()
For Each thing as Thing in duplicates
Console.WriteLine("{0}:{1}", thing.Name, thing.ServiceGroup)
Next
End Sub
End Module