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?