public override bool Equals(object obj) { if (!(obj is AnotherCustomer)) { return(false); } AnotherCustomer item = (AnotherCustomer)obj; return(Id.Equals(item.Id)); }
public static int CompareBy <T>(Func <AnotherCustomer, T> comparison, AnotherCustomer x, AnotherCustomer y) { if (comparison == null) { throw new ArgumentNullException(nameof(comparison)); } IComparable a = comparison(x) as IComparable; if (a == null) { throw new ArgumentException(nameof(comparison)); } return(a.CompareTo(comparison(y))); }
static void Main(string[] args) { var c = new Customer() { Id = 10, Name = "bbb", LastName = "zzz" }; var c1 = new Customer() { Id = 10, Name = "ccc", LastName = "yyy" }; Console.WriteLine(Customer.CompareBy(e => e.LastName, c, c1)); var c2 = new AnotherCustomer() { Id = 10, Name = "bbb", LastName = "fff" }; var c3 = new AnotherCustomer() { Id = 10, Name = "ccc", LastName = "yyy" }; Console.WriteLine(AnotherCustomer.CompareBy(e => e.Id, c2, c3)); Console.WriteLine(c2 > c3); }
public static bool LessThan(AnotherCustomer x, AnotherCustomer y) { return(string.Compare(x.Name, y.Name) < 0); }
public static bool GreaterThan(AnotherCustomer x, AnotherCustomer y) { return(string.Compare(x.Name, y.Name) > 0); }