Removing Redundant Data from a List<T>
Posted
by
Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2012-04-01T22:43:56Z
Indexed on
2012/04/01
23:30 UTC
Read the original article
Hit count: 235
I have a List of objects which are ordered. I would like to remove redundant objects where redundant does not necessarily mean duplicate. Here is an example:
List<Point> points = new List<Point>
{
new Point(0, 10),
new Point(1, 12),
new Point(2, 16),
new Point(3, 16),
new Point(4, 16),
new Point(5, 13),
new Point(6, 16),
};
I am interested in removing the new Point(3, 16)
entry because it doesn't provide useful information; I already know that the element at 2=16 and the element at 4=16. The information that 3=16 doesn't do me any good in my application (because I already have the bounds {2,4}=16), so I would like to remove that entry. I'd also like to not that I want to keep the 5th and 6th entry because there are not consecutive entries where Y=16.
Is there a slick way to do this with linq?
© Stack Overflow or respective owner