c#删除list中的元素
2013-09-29 15:02
288 查看
publicstaticvoidTestRemove(){ string[]str={"1","2","d","x"}; List<string>list=newList<string>(str); #regionhaserror for(inti=0;i<list.Count;i++) { Console.WriteLine(list[i]); Console.WriteLine("Result:"+i+":"+i/2); if(i%2==0) { list.Remove(list[i]); } } #endregion Console.WriteLine("============================================"); list=newList<string>(str); for(inti=list.Count-1;i>=0;i--) { Console.WriteLine(list[i]); Console.WriteLine("Result:"+i+":"+i/2); if(i%2==0) { Console.WriteLine(string.Format("delete.index:{0}value:{1}",i,list[i])); list.Remove(list[i]); } } }
output:
1
Result:0:0
d
Result:1:0
x
Result:2:1
============================================
x
Result:3:1
d
Result:2:1
delete.index:2value:d
2
Result:1:0
1
Result:0:0
delete.index:0value:1
.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}
相关文章推荐
- C#遍历List并删除某个或者几个元素的方法
- c#删除 list中的元素
- 造轮子:c#删除 list中的元素
- C#循环删除List中某个元素
- C#遍历List并删除某个元素的方法
- c# list 删除重复元素
- C#遍历List并删除元素的方法概述
- C# 遍历List 并删除某个元素
- c#删除 list中的元素
- C#遍历List并删除某个或者几个元素的方法
- 用Unity时,C#中List删除元素时出错
- 删除map、list集合元素总结
- Java中循环删除List中元素总结
- Java中循环删除List中元素总结
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- Python list循环删除元素
- list集合根据条件删除元素
- Python list删除元素
- vector iterators incompatible 删除map,list中元素时,应注意的问题
- 遍历删除List中的元素,会报错?