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

Standup meetings

Standup meetings Why have a Teams channel where everyone can post what they are struggling with, so anyone can respond to help and start a 1-on-1 call. If we can have 15-min meetings informing everyone once a day.

read more

Complexity <> Sophisticated

Complexity <> Sophisticated It can be just overly complex, because the person who created it didn't understand it well enough. Teachers face the challenge of breaking down complex subjects for their students. The ability to simplify abstract ideas without losing...

read more
Share This