CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
Thing unique1 = new Thing("test", 1);
Thing unique2 = new Thing("test1", 1);
Thing unique3 = new Thing("test", 2);
Thing dup1 = new Thing("test", 1);
Thing dup2 = new Thing("test", 1);
Thing[] things = {
unique1,
unique2,
unique3,
dup1,
dup2
};
List<Thing> duplicateThings =
things
.GroupBy(thing => new { thing.Name, thing.ServiceGroup })
.Where(group => group.Count() > 1)
.SelectMany(group => group.ToList())
.ToList();
foreach(Thing thing in duplicateThings)
{
Console.WriteLine("{0}:{1}", thing.Name, thing.ServiceGroup);
}
}
public class Thing
{
public string Name { get; set; }
public int ServiceGroup { get; set; }
public Thing(string name, int serviceGroup)
{
this.Name = name;
this.ServiceGroup = serviceGroup;
}
public Thing()
{
}
}
}