更新时间:2022-10-28 15:23:16
for
循环是一种结构,表示执行此操作 n. 次".>
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"