list 对象排重
来源:互联网 发布:淘宝lolita鞋子 编辑:程序博客网 时间:2024/05/17 21:40
class ListDistinctDemo { static void Main(string[] args) { List<Person> personList = new List<Person>(){ new Person(3),//重复数据 new Person(3), new Person(2), new Person(1) }; //使用匿名方法 List<Person> delegateList = personList.Distinct(new Compare<Person>( delegate(Person x, Person y) { if (null == x || null == y) return false; return x.ID == y.ID; })).ToList(); delegateList.ForEach(s => Console.WriteLine(s.ID)); //使用 Lambda 表达式 List<Person> lambdaList = personList.Distinct(new Compare<Person>( (x, y) => (null != x && null != y) && (x.ID == y.ID))).ToList(); lambdaList.ForEach(s => Console.WriteLine(s.ID)); //排序 personList.Sort((x, y) => x.ID.CompareTo(y.ID)); personList.ForEach(s => Console.WriteLine(s.ID)); } } public class Person { public int ID { get; set; } public string Name { get; set; } public Person(int id) { this.ID = id; } } public delegate bool EqualsComparer<T>(T x, T y); public class Compare<T> : IEqualityComparer<T> { private EqualsComparer<T> _equalsComparer; public Compare(EqualsComparer<T> equalsComparer) { this._equalsComparer = equalsComparer; } public bool Equals(T x, T y) { if (null != this._equalsComparer) return this._equalsComparer(x, y); else return false; } public int GetHashCode(T obj) { return obj.ToString().GetHashCode(); } }
0 0
- list 对象排重
- List集合排重/排序
- 集合 List<T> 排重方法 Distinct()
- List<对象>去重
- List<对象>去重
- list对象去重
- list中对象去重
- List对象去重操作
- Java List<对象>去重
- 排重
- Linq为对象List数据去重
- list 对象去重并排序
- JAVA-List对象某个字段去重
- List集合对象去重-项目实战
- 对于数据封装在List<Map<String,Object>>的排重问题
- sql数据排重
- php-数组排重
- C 数组排重
- 电信141p51第9题
- 【LeetCode】028.Implement strStr()
- UI_UITableView
- 《跨界杂谈》企业商业模式(七):其他
- 单元测试注意事项总结
- list 对象排重
- Selenium Webdriver firefox 浏览器问题
- hdu 1997 汉诺塔VII(递归)
- Jeditable - jQuery就地编辑插件的使用
- 两道练习题
- JS 调用函数时有括号跟没括号的区别
- Codeforces Round #297 (Div. 2) -- D. Arthur and Walls (判断矩形)
- 设计模式-适配器模式(adapter pattern)
- iOS入门