Framework Fundamentals - Char

  • A C# char represents a single Unicode Character and it is defined in System namespace as System.char struct.
  • System.Char defines a range of static methods for working with characters, such as ToUpper(), ToLower(), and IsWhiteSpace(), please refer the table below for reference.
  • As you can refer from the last column of the table above, all the characters are categorized, if a character does not fall under any of categories given above, then it is considered as invalid character.
  • All these methods are culture-sensitive.
  • To check a character validity you can call static method char.GetUnicodeCategory(), if the result is UnicodeCategory.OtherNotAssigned, then character is invalid.
  • Example
            char a = 'a';
            Console.WriteLine(char.GetUnicodeCategory(a).ToString());  //LowercaseLetter
  • By default, a Char is 16 bits wide, and it is enough to represent all normal Unicode characters(called as Basic Multilingual Plane), Some special characters may need extra space, we will see about that in later posts.

No comments:

Post a Comment

Framework Fundamentals - String - Comparing Strings

In comparing two values, the .NET Framework differentiates the concepts of equality comparison and order comparison . Equality compariso...