The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
For mine a string.HasValue() is less explit in intention
- it doesn't really speak to what happens if string itself is NULL (as compared to the empty string "".)
- or does it mean string (itself) has a value, or THE string has a value? and is empty string not a "value": the value is AN empty string.
!string.IsNullOrEmpty() yes more wordy/longer but it does specifically talk to both NULL and the empty string.
btw: I find myself using string.IsNullOrWhiteSpace() more often which one could argue doesn't speak to the empty string: i.e. "" is not NULL but pedantically nor is it white space.
... they should rename that: string.IsNullOrEmptyOrWhiteSpace(),
and why not: string.IsNotNullNorEmptyNorWhitespace() ???
and just for completion: string.IsNullOrEmptyOrWhiteSpaceOrSpecials() / string.IsNotNullNorEmptyNorWhitespaceNorSpecials()
In my case, I think the function is explainable to the team. The goal was to inverse the !string.IsNullOrEmpty to read positive. It is an attempt to follow how nullable booleans, integers, etc.. contain a HasValue function.
Again, the IsNot still sounds "negative" to me which was the goal of the extension method.
I'd agree with Lopati - IsNullOrEmpty is a specific question (as is IsNullOrWhitespace) which specifies exactly what conditions it checks for: HasValue doesn't, it implies a degree of "valueness" which is not implicit to a string, but is added by context. HasValue could mean "has a valid numeric", "has a name and address" which "IsNullOrEmpty" doesn't - it's a basic generic check which prepares the way for more explicit "value" checking.
I'll stick with IsNullOrWhitespace myself!
Sent from my Amstrad PC 1640 Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
I think it mostly depends on how the string identifies itself at any given moment - this is for all the snowflakes out ther (you know who you are).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013