How to check if a string is really empty with C#
24 September, 2021
5
5
1
Contributors
To be, or not to be (empty), that is the question...
Do it from scratch
myString
is empty." "
, passed to the IsStringEmpty
method, will return true..NET native methods: String.IsNullOrEmpty and String.IsNullOrWhitespace
String.IsNullOrEmpty
checks only if the string passed as parameter has at least one symbol, so it doesn't recognize strings composed by empty characters.String.IsNullOrWhitespace
covers the scenario described in this post. It checks both empty characters and for escape characters.Wrapping up
csharp
dotnet