有沒有辦法讓此代碼更有效?當索引不包含在另一個列表中時,從索引中刪除
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