Skip to content

Distinct

Hendrik Bulens edited this page Jul 21, 2021 · 2 revisions
List<Tuple<int, Customer>> customers = new()
{
  new Tuple<int, Customer>(1, new Customer(1, "Category 1", "Address 1")),
  new Tuple<int, Customer>(2, new Customer(2, "Category 2", "Address 1")),
  new Tuple<int, Customer>(3, new Customer(3, "Category 1", "Address 1")),
  new Tuple<int, Customer>(4, new Customer(4, "Category 3", "Address 1")),
  new Tuple<int, Customer>(5, new Customer(5, "Category 1", "Address 1")),
  new Tuple<int, Customer>(6, new Customer(6, "Category 2", "Address 1"))
};

customers.DistinctBy(x => x.Name).Count(); // Returns 3
Clone this wiki locally