Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0229 UTF-16 Character

.Net framework uses UTF-16 to store strings and characters. In UTF-16 characters occupy one or two 16 bits storage, while char type in C# only uses one 16 bits. Two-16-bits characters are called surrogates. The following code shows how to check if a char is a surrogate. using System; using System.Text; class Sample { public static void Main() { char ch = 'a'; Console.WriteLine(char.IsSurrogate(ch)); } } The output: False