如何在c#中动态创建对象 [英] How to create object dynamically in c#

查看:85
本文介绍了如何在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);
    }


这篇关于如何在c#中动态创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆