.NET 4 adds new method called string.IsNullOrWhiteSpace() which checks for spaces, empty or null. This is a nice time-saver for developers.. This static method returns true if a string is full of whitespace characters. Let us consider the below example . static void Main() { string strTest = "Simple Talk"; string strNull = null; string strEmpty = string.Empty; string strWhiteSpace = "\t\r\n\n "; Console.WriteLine("Is null or whitespace Exmaple!!"); Console.WriteLine("TestSting: " + string.IsNullOrWhiteSpace(strTest));//false Console.WriteLine("NullString: " + string.IsNullOrWhiteSpace(strNull)); //true Console.WriteLine("EmptyString: " + string.IsNullOrWhiteSpace(strEmpty)); //true Console.WriteLine("WhiteSpaceString: " + string.IsNullOrWhiteSpace(strWhiteSpace)); //true Console.ReadLine(); }
I love Programming, and Eager to learn New things Curious about Microsoft Products, Interested in Knowledge sharing. If you can dream IT, You can become it, If you can think IT, You can do IT, If you can believe it, you can achieve IT.