标签:span string new where ons cond alc oid ret
class Program { static void Main(string[] args) { Console.ReadKey(); } static int Compare(Product x, Product y) { return PartialComparer.Compare(x.Name, y.Name) ?? PartialComparer.Compare(x.Age, y.Age) ?? PartialComparer.Compare(x.Popularity, y.Popularity) ?? 0; } } public class Product { public string Name { get; set; } public int Age { get; set; } public string Popularity { get; set; } } public static class PartialComparer { public static int? Compare<T>(T first, T second) { return Compare(Comparer<T>.Default, first, second); } public static int? Compare<T>(IComparer<T> compare, T first, T second) { int ret = compare.Compare(first, second); return ret == 0 ? new int?() : ret; } public static int? ReferenceCompare<T>(T first, T second) where T : class { return first == second ? 0 : first == null ? -1 : second == null ? 1 : new int?(); } }
标签:span string new where ons cond alc oid ret
原文地址:https://www.cnblogs.com/kikyoqiang/p/9998243.html