Filter Type: All Time (0 Results) Past 24 Hours Past Week Past month Post Your Comments?
All Time (0 Results)
Past 24 Hours
Past Week
Past month
Luckily, there are several ways to get an index variable with foreach: Declare an integer variable before the loop, and then increase that one inside the loop with each loop cycle. Create a tuple that returns both the element’s value and its index. Or swap the foreach loop with the for loop.
The foreach loop iterates through each item, hence called foreach loop. Before moving forward with foreach loop, visit: Here iterable-item can be an array or a class of collection. How foreach loop works? The in keyword used along with foreach loop is used to iterate over the iterable-item.
Counter in foreach loop in C#. foreach is a loop which iterates through a collection or array one by one, starting from 0 index till the last item of the collection.