Unlock the power of .NET’s latest collection types!

by Jul 9, 2024

Unlock the power of .NET’s latest collection types!

Here’s a guide for when to best use the new Readonly, Immutable, and Frozen collections. You won’t believe how it can optimize your code! 👇

1️⃣ Readonly

Readonly is a readonly view of the original collection it was created from.

Useful to return to callers to indicate it is only for readonly use.

Keep in mind: It is still possible to update the underlying original collection.

2️⃣ Immutable

Immutable collection really can’t be changed after creation.

But it still has methods Add(), Remove() and Replace()? You can change the collection, but every change will return a new Immutable collection! It does internal linking to make sure it is still memory optimized.

Immutable is perfect for thread-safe modifications. Modifications are amazingly fast. No need for the slower Concurrency collections.

3️⃣ Frozen

Frozen collections are also readonly, but optimized like crazy for read access.

How? When you create a Frozen collection, it will find the best algorithm and structure to represent your data for read-heavy scenarios. Downside: it will cost more time to create the collection.

Frozen is a good fit, when you create it once (for example at the start of your app) and use it many times to lookup stuff.

Are any of these new collections useful for you?

Remy van Duijkeren

Remy van Duijkeren

Power Platform Advisor

Microsoft Power Platform Advisor with over 25 years of experience in IT with a focus on (marketing) automation and integration.

Helping organizations with scaling their business by automating processes on the Power Platform (Dynamics 365).

Expert in Power Platform, Dynamics 365 (Marketing & Sales) and Azure Integration Services. Giving advice and strategy consultancy.

Services:
– Strategy and tactics advise
– Automating and integrating

Subscribe to
The Daily Friction

A daily newsletter on automation and eliminating friction

Related Content

Progressive Enhancement for JS is overrated.

Progressive Enhancement for JS is overrated. In today’s web, HTML + CSS + JS is a package deal. Almost every browser supports the trio, and let’s be real: users expect apps to work smoothly with JavaScript. 95%+ of users have JS enabled – why build for the exception?...

read more

Alpine.js just clicked. 🎯

Alpine.js just clicked. 🎯 Its declarative syntax—attributes on HTML tags—is perfect for simple UI logic. Most of the time, I don’t even need to touch JavaScript. And when I do? I can write just a little bit, and it fits right in. What’s even better? The declarative...

read more

HTMX + ASPNET Core Razor = magic. ✨

HTMX + ASPNET Core Razor = magic. ✨ But HyperScript? Not so much. 😅 As a developer, I gave HyperScript a try for client-side interactions. I really wanted to love it—especially since it’s from the same creator as HTMX. But every time I used it, I spent way too much...

read more