标签:model int 一个 string compare ret col eal set
public class KeyValuePairModel { public string Name { get; set; } public string Code { get; set; } } // 这里底层会先判断比较的对象是否是同一个对象 首先会调用GetHashCode 如果不是同一对象才会调用Equals方法。 public class KeyValuePairRowComparer : IEqualityComparer<KeyValuePairModel> { public bool Equals(KeyValuePairModel t1, KeyValuePairModel t2) { return (t1.Name == t2.Name && t1.Code == t2.Code); } public int GetHashCode(KeyValuePairModel t) { return t.ToString().GetHashCode(); } }
arealist.Select(c => new KeyValuePairModel() { Code = c.CityCode, Name = c.CityName }).Distinct(new KeyValuePairRowComparer())
标签:model int 一个 string compare ret col eal set
原文地址:https://www.cnblogs.com/chongyao/p/12357899.html