Steven Giesel 6/2/2025

Why is enumerating over List faster than IList?

Read Original

This technical article analyzes a C# performance benchmark showing that enumerating a List<T> is significantly faster than enumerating an IList<T>. It explains the two main reasons: the IList<T> enumerator causes a 40-byte allocation due to boxing of a struct, and the virtual method calls required for the interface dispatch add further overhead compared to direct calls on the concrete List<T> type.

Why is enumerating over List faster than IList?

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