比如
class lei
{
int a1;
string a2;
}
list<lei> leiList=new list<lei>()
private void button1_Click(object sender, EventArgs e)
{
for(int i=0;i<10;i++)
{
lei tmp=new lei();
tmp.a1=i;
leiList.Add(tmp)
}
} private void button3_Click(object sender, EventArgs e)
{
for(int i=0;i<leiList.Count;i++)
{
// if(leiList[i].a1>3) leiList.RemoveAt(i);
//或 tmp=leiList[i];if(tmp.a1>3) leiList.RemoveAt(tmp);
}
}
这样貌似都不对。
class lei
{
int a1;
string a2;
}
list<lei> leiList=new list<lei>()
private void button1_Click(object sender, EventArgs e)
{
for(int i=0;i<10;i++)
{
lei tmp=new lei();
tmp.a1=i;
leiList.Add(tmp)
}
} private void button3_Click(object sender, EventArgs e)
{
for(int i=0;i<leiList.Count;i++)
{
// if(leiList[i].a1>3) leiList.RemoveAt(i);
//或 tmp=leiList[i];if(tmp.a1>3) leiList.RemoveAt(tmp);
}
}
这样貌似都不对。
{
if(leiList[i].a1>3)
{
leiList.RemoveAt(i);
}
foreach(YourClass cl in YourClassListObj)
{
if("条件")
{
YourClassListObj.Remove(cl);
}
}
List<int> sub = li.FindAll(DualNumber);
foreach (var di in sub)
{
Console.WriteLine(di);
} li.RemoveAll(DualNumber);
foreach (var i in li)
{
Console.WriteLine(i);
}static bool DualNumber(int v)
{
if (v % 2 == 0)
{
return true;
}
else
{
return false;
}
}
li.RemoveAll(i => (i % 2) == 0);
private void button3_Click(object sender, EventArgs e)
{
List<Lei> TempList = new List<lei>();
TempList.AddRange(leiList); // 复制到局部变量
for(int i=0;i <TempList.Count;i++)
{
tmp=TempList[i];
if(tmp.a1>3) leiList.RemoveAt(tmp);
}
}
leiList.RemoveAll(
delegate(Lei l)
{
return l.a1 > 3;
}
);