namespace test1
{
class text5
{
static void Main(string[] args)
{
List<person> prs = new List<person>();
for (int i = 0; i < 5; i++)
{
prs[i].num[i] = i;//在这个位置出现这个错误,嵌套使用索引超出范围。必须为非负值并小于集合大小。
}
for (int i = 0; i < prs.Count;i++ )
{
Console.WriteLine(prs[i].num[i]);
}
Console.Read();
}
}
class person
{
public string name;
public List<int> num = new List<int>();
}
}
请各位大侠给予帮助
解决方案 »
- 假如一个类有10个变量name0,name1,name2,…name9.只是后缀不同,为依次递增。想运行时通过for循环,依次对其赋值,怎么实现。
- 求一正则表达式 取shortcut
- 朋友们!什么是?
- RSS的问题,不能自动生成,大侠救命(急 100分)
- 为什么MessageBox函数不能在类中显示呢?
- Socket最多一次可以接收多少字节???
- 各位大大,如何vs写dll
- 操作数据的奇怪问题
- 在WEB自定义控件中为何无法得到已添加控件的clientid
- 请问如何声明一个Delegate,能否将这个Dalegate作为参数传递
- 哪位大哥可以给个C#监听器的例子看看 ~~ 最好有详细注释的
- 关于Math.Exp()
这个直接就是空的,哪里来的i给你调用啊
namespace test1
{
class text5
{
static void Main(string[] args)
{
List<person> prs = new List<person>();
for (int i = 0; i < 5; i++)
{
prs.Add(new person());
prs[i].num[i] = i;
}
for (int i = 0; i < prs.Count;i++ )
{
Console.WriteLine(prs[i].num[i]);
}
Console.Read();
}
}
class person
{
public person(0)
{
for(int i = 0; i < 5; i++) num.Add(0);
}
public string name;
public List<int> num = new List<int>();
}
}
class person
{
public person()
{
for(int i = 0; i < 5; i++) num.Add(0);
}
public string name;
public List<int> num = new List<int>();
}