Thomas Levesque 11/18/2019

Using foreach with index in C#

Read Original

This article addresses a common C# programming challenge: accessing the current index while iterating with a foreach loop. It explains the limitations of manual index tracking or using a for loop, and presents a clean solution using a custom Linq extension method that returns tuples of (item, index). This allows developers to enjoy the simplicity of foreach while still having access to the iteration index.

Using foreach with index in C#

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week