我如何获取每个循环计数 [英] how do i get for-each loop count
本文介绍了我如何获取每个循环计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?xml version="1.0" encoding="utf-8"?>
<math>
<number>2</number>
<number>3</number>
<number>4</number>
<number>5</number>
</math>
我已经编写了foreach循环来获取值并将其显示为html格式的报告.
现在我只想计算foreach循环的迭代次数.我在Google花了更多时间,但找不到结果.
在此先谢谢您.
i have written foreach loop to get values and display it as report in html format.
now i just wan to count number iterations of foreach loop. i spent more time in google but i could''t find result.
Thanks in advance.
推荐答案
您必须手动执行-没有可以访问的循环计数"(甚至可能存在-请参阅IInumerable以获取相关信息)详细信息)
You have to do it manually - there is no "loop count" you can get access to (or probably even that exists - see IInumerable for details)
int count = 0;
foreach (Item i in Collection)
{
count++;
...
}
这篇关于我如何获取每个循环计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文