CSharp - System.Char Type

Introduction

System.Char defines a range of static methods for working with characters.

For example, You can use ToUpper to convert a char to its upper case.

You can call these through either the System.Char type or its char alias:

Demo

using System;
class MainClass{/*w w  w .ja v  a2s . com*/
   public static void Main(string[] args){
         Console.WriteLine (System.Char.ToUpper ('c'));    // C
         Console.WriteLine (char.IsWhiteSpace ('\t'));     // True
   }
}

Result

ToUpper and ToLower honor the end user's locale.

System.Char and System.String provides culture-invariant versions of ToUpper and ToLower ending with the word Invariant.

These always apply English culture rules:

Console.WriteLine (char.ToUpperInvariant ('i'));    // I

This is a shortcut for:

Console.WriteLine (char.ToUpper ('i', CultureInfo.InvariantCulture))

The following table lists static methods related to categorizing characters.

Static method
Characters included
IsLetter
A-Z, a-z, and letters of other alphabets
IsUpper
Uppercase letters
IsLower
Lowercase letters
IsDigit
0-9 plus digits of other alphabets
IsLetterOrDigit
Letters plus digits
IsNumber

All digits plus Unicode fractions and Roman
numeral symbols
IsSeparator
Space plus all Unicode separator characters
IsWhiteSpace
All separators plus \n, \r, \t, \f, and \v
IsPunctuation

Symbols used for punctuation in Western and
other alphabets
IsSymbol
Most other printable symbols
Static method
Characters included
IsControl


Nonprintable "control" characters below 0x20, (None)
such as \r, \n, \t, \0, and characters between
0x7F and 0x9A