How do I skip an iteration of a `foreach` loop?

后端 未结 8 1848
野趣味
野趣味 2020-12-22 16:02

In Perl I can skip a foreach (or any loop) iteration with a next; command.

Is there a way to skip over an iteration and jump to the next loop in C#?

8条回答
  •  情话喂你
    2020-12-22 16:46

    The easiest way to do that is like below:

    //Skip First Iteration
    
    foreach ( int number in numbers.Skip(1))
    
    //Skip any other like 5th iteration
    
    foreach ( int number in numbers.Skip(5))
    

提交回复
热议问题