C# Improving string.IsNullOrEmpty readability

string.IsNullOrEmpty

HasValue

if (!string.IsNullOrEmpty(myString)) { // Do something }

Creating a String Extension

public static class StringExtensions { public static bool HasValue(this string value) { return !string.IsNullOrEmpty(value); } }

HasValue

if (myString.HasValue()) { // Do something }

HasValue

I often find myself using this great C# function:. It is the assured way to confirm whether a string is empty - null or otherwise. However, I often find myself wanting to know when it is not empty, so I wrote an string extension namedThus I have to write an if statement that reads more like this:I personally do not find this very readable because of the ! at the start of the if statement.Enter this little handy tidbit of code - a string extension - to improve readability:Inside the functioncontains the same if condition defined above. Now however, I can use the string extension method as follows:This of course matches the similar concept with nullable booleans or integers where they contain a built-incheck.Thought I'd share as I previously stated Developers are authors and this makes your code much more readable.