有没有办法让此代码更有效?当索引不包含在另一个列表中时,从索引中删除
if (includeRows != null && includeRows.Count > 0)
{
for (int i = aList.Count - 1; i >= 0; i--)
{
if (!includeRows.Exists(j => j == (i + 1)))
{
aList.RemoveAt(i);
includeRows.Remove(i + 1);
}
}
}
这是我做什么,在ALIST包含对象不是整数,因此所需要的对象的指数在list.Not知道如果includeRows.Remove()将使其减少或更高效,includeRows是只是改成了HashSet。
for (int i = aList.Count - 1; i >= 0; i--) {
if (!includeRows.Contains(i + 1))
{
aList.RemoveAt(i);
// includeRows.Remove(i + 1);
}
}
让你有索引的列表,你想从另一个列表中删除未包含在索引中的项目? – Nahum 2013-04-10 05:18:31
是----------- – tsukimi 2013-04-10 05:25:52