12 在Foreach循环中如何获得当前迭代的索引
2014-06-23 00:44
218 查看
static void ForEachIndex() { int curIndex = 0; Dictionary<string, string> diction = new Dictionary<string,string>(); int counter = 0; diction.Add("One", "One"); diction.Add("Two", "Two"); diction.Add("Three", "Three"); diction.Add("Four", "Four"); diction.Add("Five", "Five"); diction.Add("Six", "Six"); diction.Add("Seven", "Seven"); foreach (Object obj in diction) { Console.WriteLine(counter); counter++; } List<String> stringList = new List<string>(); stringList.Add("One"); stringList.Add("Two"); stringList.Add("Three"); stringList.Add("Four"); stringList.Add("Five"); stringList.Add("Six"); stringList.Add("Seven"); foreach(String str in stringList) { curIndex = stringList.IndexOf(str); Console.WriteLine(curIndex.ToString()); } System.Collections.ArrayList arList = new ArrayList(); arList.Add("One"); arList.Add("Two"); arList.Add("Three"); arList.Add("Four"); arList.Add("Five"); arList.Add("Six"); arList.Add("Seven"); foreach (String str in arList) { curIndex = arList.IndexOf(str); Console.WriteLine(curIndex.ToString()); } }
相关文章推荐
- python的for如何获得当前循环次数?
- foreach获取当前迭代索引
- GridView中如何获得点击的当前行的索引?
- velocity第五个应用例子---获得当前迭代的索引
- c:forEach varStatus属性 current当前这次迭代的(集合中的)项 index当前这次迭代从 0 开始的迭代索引 count当前这次迭代从 1 开始的迭代计数 first用来表明
- C#如何获得当前程序所在的目录
- 如何获得textBox当前光标位置
- FAQ:在SAS中如何获得当前正在运行的批作业或者交互式作业的文件名?
- 在编写触发器事件时如何获得当前插入记录的字段值?(MS SQL Server)
- 如何获得当前编辑行的句柄(网格控件)
- 在C#里怎样获得当前Windows操作系统的语言种类?以及如何知道当前Windows版本?
- BCB如何获得当前所有可视窗口的窗口标题和窗口句柄
- 如何获得当前执行程序所在的路径
- dedecms中如何在栏目列表和文章页面中获得当前栏目标题
- 如何在GridView的RowDeleting事件中获得当前行的DataKey值
- 如何获得当前应用程序所在路径
- 如何获得数据库里有多少个全文索引。删除全文索引的方法 SQL server 2005
- 如何获得当前所在的DLL模块名称
- 如何获得当前数据库的SCN值
- 如何用C#和SQL获得当前月的第一天和最后一天