- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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# Program to check a string for whitespace characters or null
This method returns true if the entered string has only whitespace characters or is null.
Let’s say you are checking for whitespace character.
bool val1 = string.IsNullOrWhiteSpace(“ “);
The above returns True, since the string is a whitespace character. In the same way, check it for null using the IsNullOrWhiteSpace() method.
Here is the entire example that checks for null and whitespace −
Example
using System; using System.IO; public class Demo { public static void Main() { bool val1 = string.IsNullOrWhiteSpace(“100”); bool val2 = string.IsNullOrWhiteSpace(" "); bool val3 = string.IsNullOrWhiteSpace(null); Console.WriteLine(val1); Console.WriteLine(val2); Console.WriteLine(val3); } }
- Related Articles
- Check if a String is whitespace, empty ("") or null in Java
- Java Program to Check if a String is Empty or Null
- Program to check we can replace characters to make a string to another string or not in C++
- C# Program to check if a character is a whitespace character
- Program to check string is palindrome with lowercase characters or not in Python
- C# program to check for URL in a String
- Check for NULL or NOT NULL values in a column in MySQL
- Check if a String is empty ("") or null in Java
- C# program to check if a string is palindrome or not
- Java program to check order of characters in string
- Python program to check if a string contains all unique characters
- C# program to check whether a given string is Heterogram or not
- C program to check if a given string is Keyword or not?
- C++ Program to check if input is an integer or a string
- C# program to check if string is panagram or not

Advertisements