這是我用來(lái)測(cè)試的代碼,T_ZJ_PostTouch還有其他字段List<T_ZJ_PostTouch> list = new List<T_ZJ_PostTouch> {new T_ZJ_PostTouch{OrgCode="1"},new T_ZJ_PostTouch{OrgCode="1"},new T_ZJ_PostTouch{OrgCode="2"},new T_ZJ_PostTouch{OrgCode="2"},}; int count = list.Distinct().Count();//結(jié)果是4int count1 = list.Distinct(new OrgCodeComparer()).Count();//結(jié)果是2 public class OrgCodeComparer : IEqualityComparer<T_ZJ_PostTouch>{public bool Equals(T_ZJ_PostTouch x, T_ZJ_PostTouch y){if (x == null)return y == null;return x.OrgCode == y.OrgCode;}public int GetHashCode(T_ZJ_PostTouch obj){if (obj == null)return 0;return obj.OrgCode.GetHashCode();}}
List Distinct()結(jié)果返回不是預(yù)期結(jié)果
慕的地6264312
2018-07-25 12:09:35