using System.Collections.Generic;
public int Id {get; set;}
public int Test {get; set;}
public class FactorComparer : IEqualityComparer<Item>
public bool Equals(Item a, Item b)
return a is not null && b is not null && a.Id == b.Id;
public int GetHashCode(Item f)
return f.Id.GetHashCode();
public static void Main()
new Item() { Id = 1, Test = 1 },
new Item() { Id = 2, Test = 1 },
new Item() { Id = 3, Test = 1 },
new Item() { Id = 3, Test = 2 },
new Item() { Id = 4, Test = 2 },
new Item() { Id = 5, Test = 2 },
var union = a.Union(b, new FactorComparer());
var distinct = a.Union(b).Distinct(new FactorComparer());
foreach (Item f in union)
Console.Write("({0} {1})", f.Id, f.Test);
foreach (Item f in distinct)
Console.Write("({0} {1})", f.Id, f.Test);