Thursday, February 11, 2010

.Net 4.0 and Visual Studio 2010 have new feature/function string.IsNullOrWhiteSpace() for strings

.Net framework 4.0 have new feature to check string.

string.IsNullOrWhiteSpace(<your input>)

Previously we had used function string.IsNullOrEmpty to check whether string is empty or null and then we execute the code. But in that case if the string has one or more white space then we had to use string.Trim() function to trim the white space. In some cases if we forget to check those conditions it may cause problems in application later.

Now with string.IsNullOrWhiteSpace we can achieve it with single line of code.

That’s a great new function in .Net 4.0 Tags:

.Net Rocks