Why is enumerating over List faster than IList?
Read OriginalThis 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.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser