# PropertyComparer<T, U> Class A object comparer that can accept a lambda expression to compare properties. ## Definition **Namespace:** CapyKit **Assembly:** CapyKit (in CapyKit.dll) Version: 1.0.0+6cdd805be49c3b769a116584ea6904955ecd820d **C#** ``` C# public class PropertyComparer : IEqualityComparer ``` **VB** ``` VB Public Class PropertyComparer(Of T, U) Implements IEqualityComparer(Of T) ``` **C++** ``` C++ generic public ref class PropertyComparer : IEqualityComparer ``` **F#** ``` F# type PropertyComparer<'T, 'U> = class interface IEqualityComparer<'T> end ```
InheritanceObject → PropertyComparer(T, U)
ImplementsIEqualityComparer(T)
#### Type Parameters
Generic type parameter of the parent object.
Generic type parameter of the property value.
## Example 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<Person, int>(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(T, U) Constructor.
## Methods
Equals(Object) Determines whether the specified object is equal to the current object.
(Inherited from Object)
Equals(T, T) Determines whether the specified properties are equal.
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode() Serves as the default hash function.
(Inherited from Object)
GetHashCode(T) Returns a hash code for the specified object.
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
ToString Returns a string that represents the current object.
(Inherited from Object)
## See Also #### Reference CapyKit Namespace