- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# IsNullOrWhiteSpace() Method
The IsNullOrWhiteSpace() method in C# is used to indicate whether a specified string is null, empty, or consists only of white-space characters.
Syntax
public static bool IsNullOrWhiteSpace (string val);
Above, the parameter val is the string to test. Let us now see an example −
Example
Let us now see an example:
using System; public class Demo { public static void Main() { string str1 = null; string str2 = String.Empty; Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1)); Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2)); } }
Output
This will produce the following output -
Is string1 null or whitespace? = True Is string2 null or whitespace? = True
Example
Let us now see another example -
using System; public class Demo { public static void Main() { string str1 = "
"; string str2 = "Tim"; Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1)); Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2)); } }
Output
Is string1 null or whitespace? = True Is string2 null or whitespace? = False
Advertisements