我谨从符合某些条件的名单中删除项目。 我举了一个例子,说明我迄今所谈到的情况:
//remove 1´s and 3´s from list of ints
List<int> indexes = new List<int>();
List<int> ints = new List<int>();
ints.Add(1);
ints.Add(2);
ints.Add(3);
foreach (int i in ints)
{
if(i == 1 || i == 3)
indexes.Add(ints.IndexOf(i));
}
indexes.Reverse();
foreach (int index in indexes)
{
ints.RemoveAt(index);
}
I am curious if the solution can be optimized? I cannot use System.Linq, I have only found the System.Data.Linq namespace as reference (Visual Studio 2005)
<>>>>>
I better had posted my real code. It is about deleting columns from a gridview
List<int> indexes = new List<int>();
foreach (Type type in types)
{
foreach (DataControlField c in entriesGrid.Columns)
{
string header = c.HeaderText;
if (header == type.Name)
{
indexes.Add(entriesGrid.Columns.IndexOf(c));
}
}
}