日期:2014-05-18 浏览次数:20789 次
List<center> centers=new List<center>();
for(int i=0;i<3;i++)
{
center ct = new center();
centers.Add(ct);
centers[i].aa=cc;//此处显示错误;索引超出范围;
centers[i].bb=i;
}
------解决方案--------------------
设断点进行调试,看列表内是否存在此索引值的元素
------解决方案--------------------
List<center> centers=new List<center>();
木有添加项,比如centers.add(...);
你的centers[i]是哪来的
------解决方案--------------------
集合中还没有任何对象,引用当然会提示越界了
应先添加对象 在对集合中的对象进行操作
------解决方案--------------------