C# 无法删除具有的项目。请删除

C# 无法删除具有的项目。请删除,c#,asp.net,arraylist,C#,Asp.net,Arraylist,我试图从arraylist中删除该项,但该项未被删除,我未收到任何错误。删除不起作用 protected void ibtnMoveUp_Click(object sender, ImageClickEventArgs e) { ArrayList ImgArry = new ArrayList(); ImgArry.Add(SelImgId); ImgArry.Add(SelImgpath);//image name Im

我试图从arraylist中删除该项,但该项未被删除,我未收到任何错误。删除不起作用

protected void ibtnMoveUp_Click(object sender, ImageClickEventArgs e)
    {
        ArrayList ImgArry = new ArrayList();
        ImgArry.Add(SelImgId);
        ImgArry.Add(SelImgpath);//image name
        ImgArry.Add(SelImgName);//image path
        List<int> t1 = new List<int>();
        if (Imgarry1 != null)
            t1 = Imgarry1;//Imaarry1 is the type List<int>
        t1.Add(Convert.ToInt32(ImgArry[0]));
        Imgarry1 = t1;
        List<ArrayList> t = new List<ArrayList>();
        if (newpath.Count > 0)// newpath is the type List<ArrayList> nd creating the viewstate
            t = newpath;
        t.Remove(ImgArry);//Item is not getting remove
        newpath = t;
        for (int i = 0; i < newpath.Count; i++)
        {
            ArrayList alst = newpath[i];
            newtb.Rows.Add(Convert.ToInt32(alst[0]), alst[1].ToString(), alst[2].ToString(), i);

        }
        dlstSelectedImages.DataSource = newtb;
        DataBind();
}
protectedvoid-ibtnMoveUp\u单击(对象发送方,ImageClickEventArgs e)
{
ArrayList ImgArry=新的ArrayList();
ImgArry.Add(SelImgId);
Add(SelImgpath);//图像名称
Add(selimname);//图像路径
列表t1=新列表();
如果(Imgarry1!=null)
t1=Imgarry1;//Imaarry1是类型列表
t1.添加(转换为32(ImgArry[0]);
Imgarry1=t1;
列表t=新列表();
if(newpath.Count>0)//newpath是创建viewstate的类型列表
t=新路径;
t、 移除(ImgArry);//项未被移除
newpath=t;
for(int i=0;i
删除正在工作,但您要通过的项未通过与列表中任何项的相等性测试


通过提供对象进行删除将尝试测试该项与列表中所有项的相等性(通常通过
.Equals()
),直到找到一个,然后将其删除。如果没有找到任何,则不会导致异常。

ImgArry
是一个局部变量,引用类型。由于
Equals()
的引用类型的默认行为实际上是
ReferenceEquals()
,您无法实现它,因为您刚才创建的实例无论如何都不能放在您的容器中

您必须先搜索不想删除的项目。例如:
t.Find(a=>a[0]==SelImgId)


然后你可以
t.Remove()
先前返回的项目。

Adam Houldsworth说写,但我用了一些不同的方法,我的代码如下

我已经移除了t.Remove(imgary);这行加了

             List<ArrayList> temp = new List<ArrayList>(t.Count);
                for (int i = 0; i < t.Count; i++)
                {
                    ArrayList al = t[i];
                    if (Convert.ToInt32(al[0]) != Convert.ToInt32(ImgArry[0]))
                        temp.Add(al);
                }
                t = temp;
List temp=新列表(t.Count);
对于(int i=0;i
请您告诉我如何卸下item@Rocky您的示例代码没有演示该问题
newpath
有条件地分配给
t
,其中可能有或可能没有任何未知类型的项。您的问题目前无法直接回答。我只能回答为什么
Remove
为“失败”。当我手动检查项目未从列表中删除,并且我的等式为pass时,这里是昨天的答案: