C
C#16mo ago
Johnnnnnnn

❔ 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...
2 Replies
Pobiega
Pobiega16mo ago
Do not replace string.isnullorwhitespace That's just taking it too far
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server