Reputation: 253
How do I create a multidimensional list of points? I googled a lot, but I didn't find a working solution.
For example:
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());
What is my mistake?
Thanks in advance.
Upvotes: 0
Views: 144
Reputation: 2879
This is an example of a multidimensional list of strings:
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]);
Or in your case:
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)"
Upvotes: 2
Reputation: 2361
See if this helps:
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());
Upvotes: 3