for和foreach有什么区别? [英] What is the difference between for and foreach?
本文介绍了for和foreach有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
和 foreach
循环之间的主要区别是什么?
在哪些情况下,我们可以使用作为
而不是 foreach
,反之亦然。 b
$ b
能用简单的程式显示吗?
两者对我来说都是一样的。我不能区分它们。
解决方案 构造说:执行此操作 n次。
a foreach
循环是一个构造,它说:对这个IEnumerable中的每个值/对象执行这个操作
What is the major difference between for
and foreach
loops?
In which scenarios can we use for
and not foreach
and vice versa.
Would it be possible to show with a simple program?
Both seem the same to me. I can't differentiate them.
解决方案
a for
loop is a construct that says "perform this operation n. times".
a foreach
loop is a construct that says "perform this operation against each value/object in this IEnumerable"
这篇关于for和foreach有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文