.NET 4 has IsNullOrWhitespace added to String class !!!
The blog was written by one of my friend, Sarang. I am publishing it here again for the reference of my friends....
Any string input can have these many possible states
1) String is null
2) String is empty
3) String contains nothing but white space
4) String has some content
Till now, .NET had static method for string bool string.IsNullOrEmpty() which handled first two conditions for us. Now with .NET 4 we have another static method
bool string.IsNullOrWhitespace()
Basically it is equivalent to the following code,
return String.IsNullOrEmpty(input) input.Trim().Length ==0 ;
but has performance improvement because white-space characters are defined by the Unicode standard. The IsNullOrWhiteSpace method interprets any character that returns a value of true when it is passed to the Char.IsWhiteSpace method as a white-space character.
We must have implemented logic for this condition everywhere in our applications but addition of this useful inbuilt function is nice to have with some performance improvement !
1 comment:
Very useful Akshay..
Keep posting blogs if you find such helpful information..
Post a Comment