How does a List know that you changed it while enumerating it?
Explains how C# List<T> detects modifications during enumeration using a version field to throw InvalidOperationException.
Explains how C# List<T> detects modifications during enumeration using a version field to throw InvalidOperationException.
Explores how to make a StringBuilder enumerable in C# using compiler duck typing and extension methods, despite it not implementing IEnumerable.
Explores how to enable foreach loops on C# types without implementing IEnumerable, using GetEnumerator methods and extension tricks.