小编Eri*_*tia的帖子

RemoveAt()不工作c#

即使在RemoveAt()方法之后,我的列表也保持不变,我甚至没有收到错误:

foreach (var row in queryCandidates.ToList())
{
    try
    {
        xString = queryCandidates.ToList().ElementAt(i).District;
        int.TryParse(xString, out xNumber);

        temp = xNumber.Equals(districtNumber);
        System.Diagnostics.Debug.Write(temp+ " ");
        System.Diagnostics.Debug.Write(i+" ");
        if (temp == false)
        {
            System.Diagnostics.Debug.WriteLine(" i is:"+i);

            //not working even when it should
            queryCandidates.ToList().RemoveAt(i);

        }
    }

    catch { }
    i++;
    if (last == i)
    {
        System.Diagnostics.Debug.WriteLine("before ending loop: ");
        return View(queryCandidates.ToList());
    }
}

System.Diagnostics.Debug.WriteLine("after ending the loop: ");
return View(queryCandidates.ToList());
Run Code Online (Sandbox Code Playgroud)

c# list removeclass removeall

2
推荐指数
1
解决办法
6757
查看次数

标签 统计

c# ×1

list ×1

removeall ×1

removeclass ×1