例子:       ArrayList list = new ArrayList();
        list = clHotel.List;//clHotel.List是取得的数据
        for (int i = 0; i < list.Count; i++)
        {
                if (((CMHotel)list[i]).Quick_hotel == "Y")
                {
                    ((CMHotel)list[i]).Name = ((CMHotel)list[i]).Name + "[Q.C]";
                    list.Remove(((CMHotel)list[i]));
                }        }怎么删除不了状态为 ’Y‘ 的数据?

解决方案 »

  1.   

    Remove的时候,ArrayList的Count和项的索引就全变了,所以问题应该是出在循环里.所以有些项你是移除不掉的.
      

  2.   

    循环移除的时候 每次remove的后面,紧跟着i--;
      

  3.   

    试试: ArrayList list = new ArrayList();
                list = clHotel.List;//clHotel.List是取得的数据 
                foreach (CMHotel hotel in list)
                {
                    if (hotel.Quick_hotel == "Y")
                    {
                        hotel.Name = hotel.Name + "[Q.C]";//这句有用吗?下面都移除了。。
                        list.Remove(hotel);
                    }
                }
      

  4.   


                foreach (CMHotel hotel in clHotel.List)
                {
                    if (hotel.Quick_hotel == "Y")
                    {
                        hotel.Name = hotel.Name + "[Q.C]";//这句有用吗?下面都移除了。。
                           clHotel.List.Remove(hotel);
                    }
                }
      

  5.   

    想移除 首先保证数组的索引不能变  。可以  先建立一个数组 ,当做中间桥梁。 
     ArrayList list = new ArrayList();
            ArrayList MoveItemlist = new ArrayList();
            list = clHotel.List;//clHotel.List是取得的数据 
            for (int i = 0; i < list.Count; i++) 
            { 
                    if (((CMHotel)list[i]).Quick_hotel == "Y") 
                    { 
                        ((CMHotel)list[i]).Name = ((CMHotel)list[i]).Name + "[Q.C]";
                        MoveItemlist.Add((CMHotel)list[i]);
                        //list.Remove(((CMHotel)list[i])); 
                    }         }
            list.Remove(MoveItemlist);
    代码没试过。
      

  6.   

    要从后面开始移除
    for (int i = list.Count-1; i >=0 ; i--)