Gets an encoding for the UTF-8 format.
Assembly: mscorlib (in mscorlib.dll)
This property returns a UTF8Encoding object that encodes Unicode (UTF-16-encoded) characters into a sequence of one to four bytes per character, and that decodes a UTF-8-encoded byte array to Unicode (UTF-16-encoded) characters. For information about the character encodings supported by the .NET Framework and a discussion of which Unicode encoding to use, see Character Encoding in the .NET Framework.
The UTF8Encoding object that is returned by this property might not have the appropriate behavior for your app.
It returns a UTF8Encoding object that uses replacement fallback to replace each string that it can't encode and each byte that it can't decode with a question mark ("?") character. Instead, you can call the UTF8Encoding::UTF8Encoding(Boolean, Boolean) constructor to instantiate a UTF8Encoding object whose fallback is either an EncoderFallbackException or a DecoderFallbackException, as the following example illustrates.
The following example defines an array that consists of the following characters:
LATIN SMALL LETTER Z (U+007A)
LATIN SMALL LETTER A (U+0061)
COMBINING BREVE (U+0306)
LATIN SMALL LETTER AE WITH ACUTE (U+01FD)
GREEK SMALL LETTER BETA (U+03B2)
A surrogate pair (U+D800 U+DD54) that forms GREEK ACROPHONIC ATTIC ONE THOUSAND STATERS (U+10154).
It displays the UTF-16 code units of each character and determines the number of bytes required by a UTF-8 encoder to encode the character array. It then encodes the characters and displays the resulting UTF-8-encoded bytes.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1