0Pricing
C# Academy · Lesson

Char Helper Methods

IsDigit, IsLetter, ToUpper.

The char Helper Methods

The char type comes with static helper methods that test or transform a character.

They live on the char type itself, so you call them like char.IsDigit(c). Most return a bool answering a yes or no question.

char c = '5';
bool isNumber = char.IsDigit(c);
// isNumber is true

char.IsDigit

char.IsDigit returns true when the character is a digit from 0 to 9.

This is great for checking user input before converting text into numbers.

class Program
{
    static void Main()
    {
        System.Console.WriteLine(char.IsDigit('8'));
        System.Console.WriteLine(char.IsDigit('x'));
    }
}

All lessons in this course

  1. The char Type
  2. Char Helper Methods
  3. Iterating Over Strings
  4. Building Strings
← Back to C# Academy