This post introduces collection expressions in C#12. It explains the code generated when using collection expressions and how they work compared to collection initializers. The post highlights the benefits of collection expressions, such as a unified syntax for different collection types, performance improvements, and

10m read timeFrom andrewlock.net
Post cover image
Table of contents
Classic collection initializersUnifying syntax with collection expressionsInferring interface types with collection expressionsEfficient automatic stackalloc for ReadOnlySpanCollection expressions make refactoring simplerEmpty collectionsBuilding collections from others with the spread elementSummary

Sort: