2016-09-15 57 views
0

如何创建点的多维列表?我GOOGLE了很多,但我没有找到一个工作解决方案。多维点列表

例如:

List<Point> lines = new List<Point>(new Point[] {}); 

Point[] points = {new Point(0, 1), new Point(2, 3)}; 
lines.AddRange(points); 

MessageBox.Show(lines[0][1].X.ToString()); 

什么是我的错?

在此先感谢。

+4

你需要一个'清单',而不是'列表' – haim770

+0

@ haim770谢谢。 – Reese

+0

@Reese如果你找到了答案,那么标记是绿色的或者你自己的答案并且标记为绿色。 –

回答

2

这是一个字符串的多维表的例子:

 List<List<string>> matrix = new List<List<string>>(); 
     List<string> track = new List<string>(); 
     track.Add("2349"); 
     track.Add("Test 123"); 
     matrix.Add(track); 

     MessageBox.Show(matrix[0][1]); 

或者你的情况:

 Point p1 = new Point(); // create new Point 
     p1.x = 5; 
     p1.y = 10; 

     List<List<Point>> points = new List<List<Point>>(); // multidimensional list of poits 

     List<Point> point = new List<Point>(); 
     point.Add(p1); // add a point to a list of point 

     points.Add(point); // add that list point to multidimensional list of points 

     MessageBox.Show(points[0][0].x); // read index 0 "(list<point>)" take index 0 of that list "(Point object)" take the value x. "(p1.x)" 
3

看看这有助于:

List<List<Point>> lines = new List<List<Point>>(); 

List<Point> points1 = new List<Point> { new Point(0, 1), new Point(2, 3) }; 
List<Point> points2 = new List<Point> { new Point(0, 1), new Point(2, 3) }; 
lines.Add(points1); 
lines.Add(points2); 

MessageBox.Show(lines[0][1].X.ToString()); 
MessageBox.Show(lines[1][1].X.ToString());