Steven Giesel 8/25/2025

Quick one: Difference between collection expressions and collection initializer

Read Original

This technical article analyzes the performance difference between C# collection expressions (e.g., `List<int> a = [1, 2, 3];`) and collection initializers (e.g., `List<int> b = new() {1,2,3};`). It shows the lowered code to demonstrate that collection expressions preallocate the list with the exact capacity, offering a potential performance benefit over initializers, which call the Add method for each element.

Quick one: Difference between collection expressions and collection initializer

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