集合的大小是固定的

dd857828142 2012-04-10 01:59:43
list.RemoveAt(index)的时候老是报错,说集合的大小是固定的,用remove也是,请问这是怎么回事。
...全文
756 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

有些列表是不允许在遍历或其他情况时删除元素
[/Quote]
应该是不要在遍历的时候删除,,, 你可以记下key的集合 然后慢慢删吧。。。、
蔡袅 2012-04-10
  • 打赏
  • 举报
回复
有些列表是不允许在遍历或其他情况时删除元素
dd857828142 2012-04-10
  • 打赏
  • 举报
回复
IList<AndroidTools2WebService.ListStorage> webListStorage = new List<AndroidTools2WebService.ListStorage>(); //这是定义

for (int i = 0; i < webListStorage.Count; i++)
{
if (webListStorage[i] == null)
continue;
string tempId = webListStorage[i].ResourceId.ToString();
if (tempId.Equals(id))
{
//移除控件中的选中项
lvImageSequence.Items.RemoveByKey(id);


int a = webListStorage.IndexOf(webListStorage[i]);

//webListStorage = tempList;


webListStorage.RemoveAt(a);

break;
}
}
}
}
}
这是后台代码
hui_play 2012-04-10
  • 打赏
  • 举报
回复
你可以做个最简单的,就是不删除,把原有的值替换掉,比如不用的统一赋值为0,不为0的就是有用的。
gxmark 2012-04-10
  • 打赏
  • 举报
回复
需要把前后代码贴出来,都不知道list是什么类型的
bdmh 2012-04-10
  • 打赏
  • 举报
回复
list是什么东西,具体点
dd857828142 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
什么集合?
[/Quote]IList集合
mngzilin 2012-04-10
  • 打赏
  • 举报
回复
什么集合?

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧