In the previous versions of .NET, we used the String.IsNullOrEmpty method to find out whether the specified string is null or an Empty string. However this method did not tell us if the string contained only whitespaces. You had to use the Trim().Length method to detect that.
.NET 4.0 makes this simpler by introducing the String.IsNullOrWhiteSpace method to find out whether a specified string is null, empty, or consists only of white-space characters.
So the following piece of code
static void Main(string[] args)
{
string str = new String(' ', 10);
Console.WriteLine(String.IsNullOrWhiteSpace(str));
Console.ReadLine();
}
will return True.
No comments:
Post a Comment