How are 4 bytes characters represented in C#
Asked Answered
L

1

9

How are 4 bytes chars are represented in C#? Like one char or a set of 2 chars?

var someCharacter = 'x'; //put 4 bytes UTF-16 character
Lobo answered 20/10, 2011 at 9:10 Comment(4)
Could you give an example of a '4 bytes char'? It would make your question clearer.Latoria
@jv42, there are some UTF-16 characters which can not be represented by 2 bytes. So it is any character with code out of 2^16Lobo
See "Unicode and .NET" article by Jon Skeet - csharpindepth.com/Articles/General/Unicode.aspxManuelmanuela
I know those chars exist, providing an example would have made certain there was not a typo in the question, especially as 'char' and 'character' meanings are sometimes confusing.Latoria
M
15

C# can only store characters from the Basic Multilingual Plane in the char type. For characters outside this plane two chars must be used - called surrogates.

You can also use a string literal such as:

string s = "\U0001D11E";

See UTF-16.

Merrymerryandrew answered 20/10, 2011 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.