如何在C#中创建运行时列表数量 [英] How to create number of lists at runtime in C#

查看:92
本文介绍了如何在C#中创建运行时列表数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为计数中的每个元素创建单独的列表。



即如果count == 4则应创建以下列表



List< polygon> List1 = new List< polygon>();

List< polygon> List2 = new List< polygon>();

List< polygon> List3 = new List< polygon>();

List< polygon> List4 =新列表< polygon>();







我需要连接列表名称所以我可以区分每个列表



如何根据运行时的计数创建这些列表

I need to create separate list for each elements in counts.

i.e if count==4 then the following list should be created

List<polygon> List1=new List<polygon>();
List<polygon> List2=new List<polygon>();
List<polygon> List3=new List<polygon>();
List<polygon> List4=new List<polygon>();



I need to concatenate the list names so that I can differentiate each list

How to create these list based on count at runtime

推荐答案

I不完全理解你的场景,但也许一系列列表可能会有帮助。
I don't understand your scenario completely but perhaps an array of lists might help.


只是在第一次声明数组。

然后在运行时添加一个数组的一个数字列表

但你必须在运行时收集数字列表,你的列表应根据它们生成
Just declare array at the first time.
Then at run time add one by one list of numbers to array
But You have to collect list of numbers in run time and your list should generate according to them


我没有得到你的情景,但我认为你正在寻找这个,

I didn't get your scenario as well, but I think you're looking for this,
int count = 5;
List<List<string>> lists = new List<List<string>>();

for (int i = 0; i < count; i++)
{
    lists.Add(new List<string>());
}

MessageBox.Show("" + lists.Count);



-KR


-KR


这篇关于如何在C#中创建运行时列表数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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