Open utterances-bot opened 3 years ago
Also, be careful as your method IsStringEmpty allocates new string each time the Trim is called (basically), this might be problematic in a loop or something. Just one more argument why not to reinvent the wheel 😀
Yes indeed! Also, if you forget to check for null
values before calling the Trim
method, you'll end up with a NullReferenceException
.
How to check if a string is really empty with C# - Code4IT
Is a string empty? What if it contains only white spaces? You shouldn't reinvent the wheel, since .NET exposes methods exactly for these cases: String.IsNullOrEmpty and String.IsNullOrWhiteSpace.
https://www.code4it.dev/blog/csharp-check-if-string-is-empty