How to Loop Through a List in C#: Every Way, Benchmarked
How to loop through and iterate a List<T> in C# with foreach, for, ForEach, Index(), and spans, plus break, continue, safe removal, and benchmarks.
I'm a Senior Customer Success Engineer at Duende Software, where I help teams succeed with Duende IdentityServer. I've been working with .NET for over a decade, and I love writing about ASP.NET Core, C#, and web development. When I'm not coding, I'm probably traveling with my wife Nicole or going on long walks with our two dogs.
How to loop through and iterate a List<T> in C# with foreach, for, ForEach, Index(), and spans, plus break, continue, safe removal, and benchmarks.
Hey there! Thanks for stopping by my little corner of the internet. I really appreciate you taking the time to visit. Whether you’re here for .NET tips, ASP.NET Core deep dives, HTMX experiments, or just stumbled in by accident — welcome!
Feel free to look around, and I hope you find something useful. 🌵