当前位置:编程学习 > C#/ASP.NET >>

C#集合的问题

我想问一下,
  我 往一个集合里边存东西,然后遍历它,如果条件满足我把它移除
但是,移除的时候,怎么才能不报错并且把集合中的每个元素都成功遍历! --------------------编程问答-------------------- C#提供的集合类已经提供好了这些功能。你用就是了。 --------------------编程问答-------------------- 不要用 foreach

用 for(int i = 最后一个,  反着干,

--------------------编程问答-------------------- 没有看明白你的意思。。。。 --------------------编程问答--------------------

for (int i = dataGridView1.Rows.Count-1; i >=0 ; i--)
{
    dataGridView1.Rows.RemoveAt(i);  //删除行
}
--------------------编程问答--------------------   List<string> aa = new List<string>();
        aa.Add("abc");
        aa.Add("123");
        foreach (string x in aa)
        {
            if (x == "123")
            {
                aa.Remove(x);
            }
        } --------------------编程问答-------------------- 上边那个有点问题,你可以用这个试下,没问题的:
 
 List<string> aa = new List<string>();
        aa.Add("abc");
        aa.Add("123");
        for (int i=0;i<aa .Count ;i++)
        {
            if (aa[i] == "123")
            {
                aa.Remove(aa[i]);
            }
        }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,