c# - How to find the items that are repeated only once in the list using LINQ -
let's have list<point> points below, how can point objects repeated 1 time in list: p(30,10) , p(30,0)
var points = new list<point> { new point { x = 0, y = 0 }, new point { x = 10, y = 20 }, new point { x = 30, y = 10 }, new point { x = 30, y = 0 }, new point { x = 0, y = 0 }, new point { x = 10, y = 20 } }; public class point { public double x; public double y; }; var query = points .groupby(p => new { p.x, p.y }) // grouping points based on (x,y). .where(g => g.count() == 1) // take groups 1 point. .select(g => g.single()); // select point in each group.
c# linq list
No comments:
Post a Comment