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


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!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

211 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements