C# Program to check if a character is a whitespace character

CsharpProgrammingServer Side Programming

Set a character with WhiteSpace −

char c = ' ';

To check if a character is a whitespace character, use the char.IsWhiteSpace method −

if (char.IsWhiteSpace(c)) {}

Let us see the complete code −

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      char c = ' ';
      if (char.IsWhiteSpace(c)) {
         Console.WriteLine("Whitespace character!");
      }
   }
}

Output

Whitespace character!
raja
Published on 05-Sep-2018 14:01:36
Advertisements