foreach循环中的最后一行 [英] Last row in foreach loop
问题描述
有没有办法知道你是否正在查看
foreach循环的最后记录记录,然后设置一个循环计数器,你手动
增量?
foreach(RaceCarCollection中的Racecar赛车)
{
...
如果最后一行做了什么?
}
你可以告诉你收藏了多少物品但是有没有办法来支付
告诉你正在寻找哪一行或者这是最后一行?
谢谢,
Tom
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in RaceCarCollection)
{
...
if last row do something?
}
You can tell how many items you have in the collection but is there way to
tell which row you are looking or if this is the last row?
Thanks,
Tom
推荐答案
tshad skrev:
tshad skrev:
有没有办法知道你是否正在查看
foreach循环其他然后设置一个循环计数器,你手动
增量?
foreach(RaceCarCollection中的Racecar赛车)
{
...
如果最后一行做某事?
}
你可以告诉你在集合中有多少项目,但有没有办法
告诉你正在寻找哪一行或者这是最后一行?
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in RaceCarCollection)
{
...
if last row do something?
}
You can tell how many items you have in the collection but is there way to
tell which row you are looking or if this is the last row?
并非没有反对RaceCarCollection.Count(或.Length)的测试
为什么不使用for循环呢?
-
Bj?rn Brox
Not without counying an test against RaceCarCollection.Count (or .Length)
Why not use a for loop instead?
--
Bj?rn Brox
2月29日,4:02 * pm,tshad < ts ... @dslextreme.comwrote:
On Feb 29, 4:02*pm, "tshad" <ts...@dslextreme.comwrote:
有没有办法知道你是否正在查看
$ b $的最后记录b foreach循环其他然后设置一个循环计数器,你手动
增量?
foreach(RaceCarCollection赛车赛车)
{
* * ...
* *如果最后一行做某事?
}
你可以告诉你收藏了多少物品但是有没有办法
告诉你正在寻找哪一行或者这是最后一行?
谢谢,
Tom
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in RaceCarCollection)
{
* * ...
* * if last row do something?
}
You can tell how many items you have in the collection but is there way to
tell which row you are looking or if this is the last row?
Thanks,
Tom
据我所知。我做过这样的事情:
foreach(int i = 0; i< collection.Count; i ++)
{
object = collection [i];
...
if(i == collection.Count - 1)
做点什么到最后一个对象
}
Not as far as I am aware of. I have done someting like this with:
foreach (int i = 0; i < collection.Count; i++)
{
object = collection[i];
...
if (i == collection.Count - 1)
do something to the last object
}
怀疑它。我总是使用一个计数器变量,并与该集合的长度相比。没什么大不了的。
- 彼得
网站: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls&更多: http://ittyurl.net
" tshad"写道:
Doubt it. I''ve always use a counter variable and compared to the length of
the collection. Not a big deal.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
"tshad" wrote:
有没有办法知道你是否正在查看
foreach循环的最后记录记录,然后设置一个循环计数器,你手动
增量?
foreach(RaceCarCollection赛车赛车)
{
...
如果最后一行做某事?
}
你可以告诉你有多少件物品在集合中,但有没有办法
告诉你正在寻找哪一行或者这是最后一行?
谢谢,
Tom
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in RaceCarCollection)
{
...
if last row do something?
}
You can tell how many items you have in the collection but is there way to
tell which row you are looking or if this is the last row?
Thanks,
Tom
这篇关于foreach循环中的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!