开发者

LinQ to collection a basic question

开发者 https://www.devze.com 2023-01-15 16:39 出处:网络
This may be too simple.Please help. List<Line> listLines = new List<Line>(); foreach (Point p in currentPointsLines)

This may be too simple.Please help.

 List<Line> listLines = new List<Line>();
 foreach (Point p in currentPointsLines)
        {
            Line l = new Line();

            l.Tag = p;
            l.X1 = AnotherList[(int)p.X].CenterX;   //AnotherList is of type Rectangle
            l.Y1 = AnotherList[(int)p.X].CenterY;
            l.X2 = AnotherList[(int)p.Y].CenterX;
            l.Y2 = AnotherList[(int)p.Y].CenterY;
            listLines.Add(l);
        }

Now I would like to query this listLines collection to get another collection of lines having x co-ordinate of Tag prope开发者_开发问答rty =1


Simply:

var query = listLines.Where(l => ((Point) l.Tag).X == 1);

If that's not what you're after, please clarify.

0

精彩评论

暂无评论...
验证码 换一张
取 消