Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Working with char

โญ beginnerโณ 12 min read๐Ÿ“ Lesson 24 of 85

Single characters, their escape codes, and the classifier methods that power validators.

char is a small integer

char c = 'A';
Console.WriteLine((int)c);     // 65 โ€” the code point
char next = (char)(c + 1);     // 'B'

A char holds a UTF-16 code unit โ€” for everyday ASCII work, think "a small number with a costume." Casting to int reveals the code; arithmetic shifts the code. That's how case conversion and letter checks work underneath.

Escapes you'll actually use

"a\tb"      // tab
"line\n"    // newline
"quote: \"" // a literal double quote
"backslash: \\" 
'a'         // char literal: single quotes, no escape needed

Inside a char literal, '\n' and '\t' work the same way; '\\'' escapes a single quote. ("\u00e9" gives 'รฉ' by code point โ€” worth knowing it exists.)

Classifiers: the validator toolkit

char.IsDigit(c)      // '0'..'9'
char.IsLetter(c)     // letters, including accented ones
char.IsLetterOrDigit(c)
char.IsWhiteSpace(c) // spaces, tabs, newlines
char.IsUpper(c) / char.IsLower(c)
char.ToLower(c) / char.ToUpper(c)

These return bool and take a char. A username validator, a digit counter, a "does this line start with whitespace" check โ€” all one-liners over these classifiers plus a loop. Prefer char.IsDigit over '0' <= c && c <= '9': it says what it does, and it's correct for more than ASCII.

โšก Now practice

Ready to Code
Text workshopImmutability discipline, case-aware searching, record splitting, and char-level validation.
4 challenges ยท ยท ~38 min