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 truechar.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
- The char Type
- Char Helper Methods
- Iterating Over Strings
- Building Strings