Get ready to simplify your collections empty check in C#!

by Feb 6, 2024

Get ready to simplify your collections empty check in C#!

Ever noticed how different collection types in C#, like Array, List, or IEnumerable, have different methods to check if they’re empty? Some ways are faster, some are slower… it’s a bit of a maze.

Well, here’s a breath of fresh air for you. Your struggles are over with the latest C# 11.

No more juggling multiple methods – just one simple, universal way:

var isEmpty = myCollection is [];

Yes, you read that right. This single line of code works for ANY collection type! And the best part? The compiler plays the hero, intelligently finding the most efficient way to perform the empty check.

Do you like the simplicity of this?


Subscribe to
The Daily Friction

A daily newsletter on automation and eliminating friction

Related Content

Improving Optimization?

Improving Optimization? The traditional steps of Optimization: 1. Eliminate 2. Automate or 3. Delegate What if we added a missing element? Simplify. Before automating a convoluted workflow or delegating a tangled task, strip away the unnecessary. Make processes leaner...

read more

Unit tests for Dataverse plugins?

Unit tests for Dataverse plugins? I must admit, I almost never write unit tests for Dataverse plugins. Plugins are often quite simple, testing them in isolation is not particularly useful. Often you only test a couple of if-statements. Unit tests don't bring a lot of...

read more

New Dynamics 365 browser extension

New Dynamics 365 browser extension I'm trying out the new -Power Roles- extension and it looks very promising. You browse to a Dynamics 365 (or Power Apps) app and then you press -record-. It will then monitor all the action you do in the app and propose which...

read more