Johnnnnnnn
Johnnnnnnn
CC#
Created by Johnnnnnnn on 8/20/2023 in #help
❔ How to replace string.IsNullOrWhiteSpace() with pattern matching?
Hi, as I understand it, MS is now suggesting that we use pattern matching as much as possible for testing values. So I try to use "is null" everywhere instead of "== null", as has been the norm up to C# 8. Does anyone here have a suggestion for how to use pattern matching to test if a string is null or whitespace? What I've come up with so far is if ("a string".Trim() is { Length: > 0 }) { ... }... The Trim() doesn't look so good in my eyes...
4 replies