While working on a project I have come across a way of not having to check if a string isnull or empty
dim sb as new stringbuilder
dim bob as string
sb.append((bob & string.empty).padLeft(10, " "))
Here, bob is not instantiated but doesn’t throw a null reference error. In situations like this, is it more readable to do the above code or the below code?
if string.isnullorempty(bob) then
sb.append(string.empty.padleft(10, " ")
else
sb.append(bob.padleft(10," "))
endif
I personally think method #1 is more readable and maintainable. What does the community feel?
Use If() with two parameters to select the first non-null value, e.g.