Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IEnumerable<T> FindDuplicates<T>(this IEnumerable<T> enumerable) {
- var hashset = new HashSet<T>();
- foreach ( var cur in enumerable ) {
- if ( !hashset.Add(cur) ) {
- yield return cur;
- }
- }
- }
- List<SomeType> list = GetTheList();
- list
- .FindDuplicates()
- .ToList()
- .ForEach(x => x.State = "DUPLICATE");
- List<obj> keys = new List<object>();
- foreach (MyObject obj in myList)
- {
- if (keys.Contains(obj.keyProperty))
- obj.state = "something indicating a duplicate here";
- else
- keys.add(obj.keyProperty)
- }
- IEnumerable<T> oldList;
- IEnumerable<T> list;
- foreach (var n in oldList.Intersect(list))
- n.State = "Duplicate";
Add Comment
Please, Sign In to add comment