动态实例化如何实现?? 就是我根据用户的信息比如用户输入5,那我就要进行5项实例化这要如何实现呢??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 caozhy 于 2013-02-26 22:23:25 编辑 List<YourClass> list = new List<YourClass>();int n = int.Parse(Console.ReadLine());for (int i = 0; i < n; i++) list.Add(new YourClass()); 楼主是想要这个效果么 int userInput = System.Int32.Parse(Console.ReadLine()); for (int i = 0; i < userInput; i++) { Console.WriteLine("i =" + i); //new something } Console.ReadLine(); 呃那要是PointF怎么做这种操作呢? 不是,比如我现在用户需要创建5个PointF的实例,要怎么自动判断需要创建多少个实例,比如6个的话它又会自动创建6个, 一样的啊List<PointF> list = new List<PointF>();int n = int.Parse(Console.ReadLine());for (int i = 0; i < n; i++) list.Add(new PointF(0.0, 0.0)); 没用过List,刚开始理解错了明早试试看,谢谢你!! 根据用户输入的数字。生成几个都无所谓的。用List<Point>或者数组都行。for就解决了。 (WINDOWS API)mouse_event问题 下载MSDN的开源软件package this问题(两贴共80分) c# 编程 c# 怎样实现在加载大量数据的时候显示“正在加载,请稍等......" 加载完后再关闭 这段文字如何解码 如果只用c#作web development,还有必要详细了解delegates and events/reflection and attributes/multithreading Visual-graph图形控件在C#中应用,有研究的来聊聊. 窗体上有若干个自定义控件,怎样实现鼠标框选啊 xsl的问题 如何测试连接 c#编写的程序怎么在一般电脑上运行? 常见问题关于C#打开另一进程问题
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
list.Add(new YourClass());
for (int i = 0; i < userInput; i++)
{
Console.WriteLine("i =" + i);
//new something
}
Console.ReadLine();
不是,比如我现在用户需要创建5个PointF的实例,要怎么自动判断需要创建多少个实例,比如6个的话它又会自动创建6个,
List<PointF> list = new List<PointF>();
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
list.Add(new PointF(0.0, 0.0));
明早试试看,谢谢你!!
用List<Point>或者数组都行。
for就解决了。