2010-09-09 51 views
0

這可能太簡單了。請幫助。LinQ收集一個基本問題

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); 
     } 

現在我想查詢該listLines收集得到具有Tag屬性= 1

回答

3

簡單的x座標系的另一個集合:

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

如果這不是你請重新澄清。

+0

如何將l.Tag轉換爲點在這個非常相同的行:-) – 2010-09-09 09:25:13

+0

@Tintu:編輯。這只是一個表演,就好像它發生在其他地方一樣。 – 2010-09-09 09:28:12

+0

謝謝Skeet.Guess,這將解決我的問題。 – 2010-09-09 09:29:55