如何在c#中动态创建对象

如何在c#中动态创建对象

问题描述:

我已经构建了一个应用程序,我正在使用谷歌地图。以下是代码段

I've built one application where i am using google maps. Here is the code snippets

GooglePoint GP1 = new GooglePoint();
        GP1.ID = "1";
        GP1.Latitude = 43.65669;
        GP1.Longitude = -79.44268;
        GP1.InfoHTML = "This is point 1";
        GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1);



现在我想在循环内动态创建此点。那我怎么能这样做呢?



提前谢谢。


Now i want to create this point dynamically inside a loop. So how can i do that?

Thanks in advance.

嗯...这是微不足道的...

Well... it's trivial...
for (int i = 1; i < 10; i++)
    {
    GooglePoint GP1 = new GooglePoint();
    GP1.ID = i.ToString();
    GP1.Latitude = 43.65669;
    GP1.Longitude = -79.44268;
    GP1.InfoHTML = string.Format("This is point {0}", i);
    GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1);
    }