Steven Giesel 4/29/2024

How does a List know that you changed it while enumerating it?

Read Original

This technical article explores the internal mechanism in C# .NET's List<T> that triggers an InvalidOperationException when a list is modified while being enumerated. It demonstrates the concept by building a custom list class and shows how a 'version' field is incremented on mutations and checked during iteration to detect changes.

How does a List know that you changed it while enumerating it?

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser