Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var duplicates = agents.GroupBy(a => a.ID).Where(a=>a.Count() > 1);
- foreach (var agent in duplicates)
- {
- Console.WriteLine(agent.Key.ToString());
- }
- public class Foo
- {
- public int ID;
- }
- var list = new List<Foo>();
- var r = new Random();
- for (int i = 0; i < 10000; i++) list.Add(new Foo { ID = r.Next() });
- var sw = new Stopwatch();
- sw.Start();
- bool b = list.Any(i => list.Where(j => i != j).Any(j => j.ID == i.ID));
- Console.WriteLine(b);
- Console.WriteLine(sw.ElapsedTicks);
- sw.Reset();
- sw.Start();
- b = (list.GroupBy(i => i.ID).Count() != list.Count);
- Console.WriteLine(b);
- Console.WriteLine(sw.ElapsedTicks);
- foreach(var agent in Agents) {
- if(Agents.Count(a => a.ID == agent.ID) > 1)
- Console.WriteLine("Found: {0}", agent.ID);
- }
- bool b = list.Any(i => list.Any(j => j.ID == i.ID && j != i));
- var duplicates = agents
- .GroupBy(a => a.ID)
- .Where(g => g.Skip(1).Any());
Add Comment
Please, Sign In to add comment