foreach循环中的最后一行

foreach循环中的最后一行

本文介绍了foreach循环中的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道你是否正在查看

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

推荐答案



并非没有反对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




据我所知。我做过这样的事情:


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
}



这篇关于foreach循环中的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:37