mirror of
https://github.com/wagesj45/CapyKit.git
synced 2024-11-12 19:23:36 -06:00
4.6 KiB
4.6 KiB
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.2
C#
public class PropertyComparer<T, U> : IEqualityComparer<T>
F#
type PropertyComparer<'T, 'U> =
class
interface IEqualityComparer<'T>
end
Inheritance | Object → PropertyComparer(T, U) |
Implements | IEqualityComparer(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) |
Fields
expression | The expression to retrieve the property. |