# Class PropertyComparer
Namespace: [CapyKit](CapyKit.md)
Assembly: CapyKit.dll
A object comparer that can accept a lambda expression to compare properties.
```csharp
public class PropertyComparer : IEqualityComparer
```
#### Type Parameters
`T`
Generic type parameter of the parent object.
`U`
Generic type parameter of the property value.
#### Inheritance
[object](https://learn.microsoft.com/dotnet/api/system.object) ←
[PropertyComparer](CapyKit.PropertyComparer\-2.md)
#### Implements
[IEqualityComparer](https://learn.microsoft.com/dotnet/api/system.collections.generic.iequalitycomparer\-1)
#### Inherited Members
[object.Equals\(object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\)),
[object.Equals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\-system\-object\)),
[object.GetHashCode\(\)](https://learn.microsoft.com/dotnet/api/system.object.gethashcode),
[object.GetType\(\)](https://learn.microsoft.com/dotnet/api/system.object.gettype),
[object.MemberwiseClone\(\)](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone),
[object.ReferenceEquals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals),
[object.ToString\(\)](https://learn.microsoft.com/dotnet/api/system.object.tostring)
#### Extension Methods
[ObjectExtensions.UpdateProperties\>\(PropertyComparer, PropertyComparer\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_\_1\_\_\_0\_\_\_0\_),
[ObjectExtensions.UpdateProperties\(object, object\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_System\_Object\_System\_Object\_)
## Examples
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var people = new List<Person>
{
new Person { Name = "Alice", Age = 30 }, new Person { Name = "Bob", Age = 30 }, new
Person { Name = "Charlie", Age = 35 }
};
var comparer = new PropertyComparer(p => p.Age);
var distinctPeople = people.Distinct(comparer).ToList();
foreach (var person in distinctPeople)
{
Console.WriteLine($"{person.Name} - {person.Age}");
}
}
}
class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
## Constructors
### PropertyComparer\(Func\)
Constructor.
```csharp
public PropertyComparer(Func expression)
```
#### Parameters
`expression` [Func](https://learn.microsoft.com/dotnet/api/system.func\-2)
The expression.
## Methods
### Equals\(T, T\)
Determines whether the specified properties are equal.
```csharp
public bool Equals(T x, T y)
```
#### Parameters
`x` T
The first object of type T to compare.
`y` T
The second object of type T to compare.
#### Returns
[bool](https://learn.microsoft.com/dotnet/api/system.boolean)
true if the specified objects are equal; otherwise,
false.
### GetHashCode\(T\)
Returns a hash code for the specified object.
```csharp
public int GetHashCode(T obj)
```
#### Parameters
`obj` T
The for which a hash code is to be returned.
#### Returns
[int](https://learn.microsoft.com/dotnet/api/system.int32)
A hash code for the specified object.
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
The type of obj is a reference type and
obj is
null.