Bald Bearded Builder
csharp/how-has-net-not-had-this-before

How has .NET not had this before!?

C# collection expressions simplify array and list creation, add spread syntax, and can support custom collection types through a builder attribute.

Loads from YouTube when you press play

Transcript 1 topic

Collection expressions in .NET

0:00

How has .net not had this before now? JavaScript and TypeScript been using it there for years, but now we get some real quality of life improvements to our collections and lists and arrays. The first improvement is simplifying newing up arrays or lists. This is behavior that looks similar. In the past, we've been able to do something kind of like that with curly braces, but in this case, much cleaner syntax.

The benefits don't end by just removing the new keyword. We also get a proper spread operator. The spread operator is something that JavaScript and TypeScript developers have had for a long time. And praise Satya, us C folks get to use it now too. Now you may need to teach your own collection classes how to handle this new spread operator, but fortunately it's not too bad.

It's just a matter of using a read only span and then adding a collection builder attribute to the class you're using. I'm curious, what are the features that are coming out that you're most excited about? Be sure to leave me a comment and I'll catch you next time.

Sign in to join in. Reading needs nothing.