user1031034
user1031034

Reputation: 856

convert string to point name

I have:

for(int b = 0; b <num; b++)
{
    string naz_pkt = "punkt_" + b.ToString();

    Point naz_pkt = new Point(i,j);
    ....
}

And what, I need to do:

I want make Points, where name of the Point will be change with the loop. And i will have for ex.

Point punkt_1 = new Point(0,1);
Point punkt_2 = new Point(0,2);
Point punkt_3 = new Point(0,3);
etc.

After that I want drow this points by polygon. Thanks for help.

Upvotes: 0

Views: 172

Answers (1)

Adrian F&#226;ciu
Adrian F&#226;ciu

Reputation: 12552

If you don't really care about the name of the points, you can use a list to hold them:

List<Point> allPoints = new List<Point>();
for(int b = 0; b < num; b++)
{
    Point naz_pkt = new Point(i,j);
    allPoints.Add(naz_pkt);
}

If you care about the name you can use something like KeyValuePair:

List<KeyValuePair<string, Point>> allPoints = new List<KeyValuePair<string, Point>>();
for (int b = 0; b < num; b++)
{
    var pointName = "punkt_" + b.ToString();
    var pointObject = new Point(i, j);
    KeyValuePair<string, Point> point = new KeyValuePair<string, Point>(pointName, pointObject);

    allPoints.Add(point);
}

Upvotes: 1

Related Questions